1
22
23 package com.liferay.portlet.workflow.service.impl;
24
25 import com.liferay.documentlibrary.DuplicateDirectoryException;
26 import com.liferay.documentlibrary.NoSuchFileException;
27 import com.liferay.portal.PortalException;
28 import com.liferay.portal.SystemException;
29 import com.liferay.portal.kernel.util.GetterUtil;
30 import com.liferay.portal.kernel.util.StringPool;
31 import com.liferay.portal.model.CompanyConstants;
32 import com.liferay.portal.model.User;
33 import com.liferay.portal.model.impl.GroupImpl;
34 import com.liferay.portlet.workflow.NoSuchDefinitionException;
35 import com.liferay.portlet.workflow.model.WorkflowDefinition;
36 import com.liferay.portlet.workflow.service.base.WorkflowDefinitionServiceBaseImpl;
37
38 import java.rmi.RemoteException;
39
40
47 public class WorkflowDefinitionServiceImpl
48 extends WorkflowDefinitionServiceBaseImpl {
49
50 public WorkflowDefinition addDefinition(
51 String xml, boolean addCommunityPermissions,
52 boolean addGuestPermissions)
53 throws PortalException, SystemException {
54
55 return addDefinition(
56 xml, Boolean.valueOf(addCommunityPermissions),
57 Boolean.valueOf(addGuestPermissions), null, null);
58 }
59
60 public WorkflowDefinition addDefinition(
61 String xml, String[] communityPermissions,
62 String[] guestPermissions)
63 throws PortalException, SystemException {
64
65 return addDefinition(
66 xml, null, null, communityPermissions, guestPermissions);
67 }
68
69 public WorkflowDefinition addDefinition(
70 String xml, Boolean addCommunityPermissions,
71 Boolean addGuestPermissions, String[] communityPermissions,
72 String[] guestPermissions)
73 throws PortalException, SystemException {
74
75 try {
76
77
79 User user = getUser();
80
81 long definitionId = GetterUtil.getLong(
82 workflowComponentService.deploy(xml));
83
84
86 long companyId = user.getCompanyId();
87 String portletId = CompanyConstants.SYSTEM_STRING;
88 long groupId = GroupImpl.DEFAULT_PARENT_GROUP_ID;
89 long repositoryId = CompanyConstants.SYSTEM;
90 String dirName = "workflow/definitions";
91 String fileName = dirName + "/" + definitionId + ".xml";
92
93 try {
94 dlService.addDirectory(companyId, repositoryId, dirName);
95 }
96 catch (DuplicateDirectoryException dde) {
97 }
98
99 dlService.addFile(
100 companyId, portletId, groupId, repositoryId, fileName,
101 StringPool.BLANK, new String[0], xml.getBytes());
102
103
105 if ((addCommunityPermissions != null) &&
106 (addGuestPermissions != null)) {
107
108 addDefinitionResources(
109 user, definitionId, addCommunityPermissions.booleanValue(),
110 addGuestPermissions.booleanValue());
111 }
112 else {
113 addDefinitionResources(
114 user, definitionId, communityPermissions, guestPermissions);
115 }
116
117 return getDefinition(definitionId);
118 }
119 catch (RemoteException re) {
120 throw new SystemException(re);
121 }
122 }
123
124 public void addDefinitionResources(
125 User user, long definitionId, boolean addCommunityPermissions,
126 boolean addGuestPermissions)
127 throws PortalException, SystemException {
128
129 resourceLocalService.addResources(
130 user.getCompanyId(), 0, user.getUserId(),
131 WorkflowDefinition.class.getName(), definitionId, false,
132 addCommunityPermissions, addGuestPermissions);
133 }
134
135 public void addDefinitionResources(
136 User user, long definitionId, String[] communityPermissions,
137 String[] guestPermissions)
138 throws PortalException, SystemException {
139
140 resourceLocalService.addModelResources(
141 user.getCompanyId(), 0, user.getUserId(),
142 WorkflowDefinition.class.getName(), definitionId,
143 communityPermissions, guestPermissions);
144 }
145
146 public WorkflowDefinition getDefinition(long definitionId)
147 throws PortalException, SystemException {
148
149 try {
150 long companyId = getUser().getCompanyId();
151 long repositoryId = CompanyConstants.SYSTEM;
152 String dirName = "workflow/definitions";
153 String fileName = dirName + "/" + definitionId + ".xml";
154
155 String xml = new String(
156 dlService.getFile(companyId, repositoryId, fileName));
157
158 WorkflowDefinition definition =
159 (WorkflowDefinition)workflowComponentService.getDefinition(
160 definitionId);
161
162 definition.setXml(xml);
163
164 return definition;
165 }
166 catch (NoSuchFileException nsfe) {
167 throw new NoSuchDefinitionException();
168 }
169 catch (RemoteException re) {
170 throw new SystemException(re);
171 }
172 }
173
174 }