001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.workflow.service.impl;
022:
023: import com.liferay.documentlibrary.DuplicateDirectoryException;
024: import com.liferay.documentlibrary.NoSuchFileException;
025: import com.liferay.portal.PortalException;
026: import com.liferay.portal.SystemException;
027: import com.liferay.portal.kernel.util.GetterUtil;
028: import com.liferay.portal.kernel.util.StringPool;
029: import com.liferay.portal.model.User;
030: import com.liferay.portal.model.impl.CompanyImpl;
031: import com.liferay.portal.model.impl.GroupImpl;
032: import com.liferay.portlet.workflow.NoSuchDefinitionException;
033: import com.liferay.portlet.workflow.model.WorkflowDefinition;
034: import com.liferay.portlet.workflow.service.base.WorkflowDefinitionServiceBaseImpl;
035:
036: import java.rmi.RemoteException;
037:
038: /**
039: * <a href="WorkflowDefinitionServiceImpl.java.html"><b><i>View Source</i></b>
040: * </a>
041: *
042: * @author Brian Wing Shun Chan
043: *
044: */
045: public class WorkflowDefinitionServiceImpl extends
046: WorkflowDefinitionServiceBaseImpl {
047:
048: public WorkflowDefinition addDefinition(String xml,
049: boolean addCommunityPermissions, boolean addGuestPermissions)
050: throws PortalException, SystemException {
051:
052: return addDefinition(xml, Boolean
053: .valueOf(addCommunityPermissions), Boolean
054: .valueOf(addGuestPermissions), null, null);
055: }
056:
057: public WorkflowDefinition addDefinition(String xml,
058: String[] communityPermissions, String[] guestPermissions)
059: throws PortalException, SystemException {
060:
061: return addDefinition(xml, null, null, communityPermissions,
062: guestPermissions);
063: }
064:
065: public WorkflowDefinition addDefinition(String xml,
066: Boolean addCommunityPermissions,
067: Boolean addGuestPermissions, String[] communityPermissions,
068: String[] guestPermissions) throws PortalException,
069: SystemException {
070:
071: try {
072:
073: // Deploy xml
074:
075: User user = getUser();
076:
077: long definitionId = GetterUtil
078: .getLong(workflowComponentService.deploy(xml));
079:
080: // File
081:
082: long companyId = user.getCompanyId();
083: String portletId = CompanyImpl.SYSTEM_STRING;
084: long groupId = GroupImpl.DEFAULT_PARENT_GROUP_ID;
085: long repositoryId = CompanyImpl.SYSTEM;
086: String dirName = "workflow/definitions";
087: String fileName = dirName + "/" + definitionId + ".xml";
088:
089: try {
090: dlService
091: .addDirectory(companyId, repositoryId, dirName);
092: } catch (DuplicateDirectoryException dde) {
093: }
094:
095: dlService.addFile(companyId, portletId, groupId,
096: repositoryId, fileName, StringPool.BLANK,
097: new String[0], xml.getBytes());
098:
099: // Resources
100:
101: if ((addCommunityPermissions != null)
102: && (addGuestPermissions != null)) {
103:
104: addDefinitionResources(user, definitionId,
105: addCommunityPermissions.booleanValue(),
106: addGuestPermissions.booleanValue());
107: } else {
108: addDefinitionResources(user, definitionId,
109: communityPermissions, guestPermissions);
110: }
111:
112: return getDefinition(definitionId);
113: } catch (RemoteException re) {
114: throw new SystemException(re);
115: }
116: }
117:
118: public void addDefinitionResources(User user, long definitionId,
119: boolean addCommunityPermissions, boolean addGuestPermissions)
120: throws PortalException, SystemException {
121:
122: resourceLocalService.addResources(user.getCompanyId(), 0, user
123: .getUserId(), WorkflowDefinition.class.getName(),
124: definitionId, false, addCommunityPermissions,
125: addGuestPermissions);
126: }
127:
128: public void addDefinitionResources(User user, long definitionId,
129: String[] communityPermissions, String[] guestPermissions)
130: throws PortalException, SystemException {
131:
132: resourceLocalService.addModelResources(user.getCompanyId(), 0,
133: user.getUserId(), WorkflowDefinition.class.getName(),
134: definitionId, communityPermissions, guestPermissions);
135: }
136:
137: public WorkflowDefinition getDefinition(long definitionId)
138: throws PortalException, SystemException {
139:
140: try {
141: long companyId = getUser().getCompanyId();
142: long repositoryId = CompanyImpl.SYSTEM;
143: String dirName = "workflow/definitions";
144: String fileName = dirName + "/" + definitionId + ".xml";
145:
146: String xml = new String(dlService.getFile(companyId,
147: repositoryId, fileName));
148:
149: WorkflowDefinition definition = (WorkflowDefinition) workflowComponentService
150: .getDefinition(definitionId);
151:
152: definition.setXml(xml);
153:
154: return definition;
155: } catch (NoSuchFileException nsfe) {
156: throw new NoSuchDefinitionException();
157: } catch (RemoteException re) {
158: throw new SystemException(re);
159: }
160: }
161:
162: }
|