Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
b63886e8cf | |||
d5c370c51c | |||
8870ade2d7 | |||
c962825397 | |||
3a3aa83128 | |||
af8025237b | |||
8945bd569b | |||
31efefbc55 | |||
f7d74a082c | |||
2cf1b241f3 |
10
pom.xml
10
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>com.inteligr8.alfresco.activiti</groupId>
|
<groupId>com.inteligr8.alfresco.activiti</groupId>
|
||||||
<artifactId>model-share-activiti-app-ext</artifactId>
|
<artifactId>model-share-activiti-app-ext</artifactId>
|
||||||
<version>1.0.5</version>
|
<version>1.0.8</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>Model Share APS Extension</name>
|
<name>Model Share APS Extension</name>
|
||||||
@@ -39,11 +39,11 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
<maven.compiler.release>11</maven.compiler.release>
|
<maven.compiler.release>17</maven.compiler.release>
|
||||||
|
|
||||||
<aps.version>2.4.1</aps.version>
|
<aps.version>2.4.4</aps.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@@ -21,6 +21,10 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.activiti.domain.idm.User;
|
||||||
|
import com.activiti.security.SecurityUtils;
|
||||||
|
import com.activiti.service.api.UserService;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ModelShareExtension implements Bootstrappable {
|
public class ModelShareExtension implements Bootstrappable {
|
||||||
|
|
||||||
@@ -28,6 +32,12 @@ public class ModelShareExtension implements Bootstrappable {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ModelShareWorker worker;
|
private ModelShareWorker worker;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@Value("${inteligr8.modelShareExtension.runAs:admin@app.activiti.com}")
|
||||||
|
private String runAsUser;
|
||||||
|
|
||||||
@Value("${inteligr8.modelShareExtension.enabled:true}")
|
@Value("${inteligr8.modelShareExtension.enabled:true}")
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
@@ -58,8 +68,14 @@ public class ModelShareExtension implements Bootstrappable {
|
|||||||
private void scheduled() {
|
private void scheduled() {
|
||||||
if (!this.enabled || !this.bootstrapped)
|
if (!this.enabled || !this.bootstrapped)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.logger.trace("scheduled()");
|
this.logger.trace("scheduled()");
|
||||||
|
|
||||||
|
this.logger.debug("Assuming user: {}", this.runAsUser);
|
||||||
|
User runAsUser = this.userService.findUserByEmail(this.runAsUser);
|
||||||
|
SecurityUtils.assumeUser(runAsUser);
|
||||||
|
this.logger.debug("Assumed user: {}", runAsUser.getId());
|
||||||
|
|
||||||
this.worker.shareAllModels();
|
this.worker.shareAllModels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@ import org.springframework.data.domain.PageRequest;
|
|||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.activiti.domain.editor.AbstractModel;
|
||||||
import com.activiti.domain.editor.Model;
|
import com.activiti.domain.editor.Model;
|
||||||
import com.activiti.domain.editor.ModelShareInfo;
|
import com.activiti.domain.editor.ModelShareInfo;
|
||||||
import com.activiti.domain.editor.SharePermission;
|
import com.activiti.domain.editor.SharePermission;
|
||||||
@@ -208,26 +209,85 @@ public class ModelShareWorker implements Bootstrappable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void shareAllModels() {
|
public void shareAllModels() {
|
||||||
if (this.tenantId != null)
|
this.shareApsFormModels();
|
||||||
this.shareAllModels(this.tenantId);
|
this.shareApsDataModels();
|
||||||
this.shareAllModels(null);
|
this.shareApsDecisionTableModels();
|
||||||
|
this.shareApsProcessModels();
|
||||||
|
this.shareApsAppModels();
|
||||||
|
|
||||||
|
if (this.tenantId != null) {
|
||||||
|
this.shareAllActivitiModels(this.tenantId);
|
||||||
|
} else {
|
||||||
|
this.shareAllActivitiModels(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shareAllModels(Long tenantId) {
|
private void shareApsFormModels() {
|
||||||
this.logger.trace("Discovering models in tenant {} ...", this.tenantId);
|
this.logger.trace("Discovering APS form models");
|
||||||
|
List<AbstractModel> models = this.modelService.getModelsByModelTypeAndReferenceId(Model.MODEL_TYPE_FORM, null);
|
||||||
|
for (AbstractModel model : models) {
|
||||||
|
this.logger.debug("Discovered APS form model: {} [{}]", model.getName(), model.getId());
|
||||||
|
this.shareModel((Model) model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shareApsDataModels() {
|
||||||
|
this.logger.trace("Discovering APS data models");
|
||||||
|
List<AbstractModel> models = this.modelService.getModelsByModelTypeAndReferenceId(Model.MODEL_TYPE_DATA_MODEL, null);
|
||||||
|
for (AbstractModel model : models) {
|
||||||
|
this.logger.debug("Discovered APS data model: {} [{}]", model.getName(), model.getId());
|
||||||
|
this.shareModel((Model) model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shareApsDecisionTableModels() {
|
||||||
|
this.logger.trace("Discovering APS decision table models");
|
||||||
|
List<AbstractModel> models = this.modelService.getModelsByModelTypeAndReferenceId(Model.MODEL_TYPE_DECISION_TABLE, null);
|
||||||
|
for (AbstractModel model : models) {
|
||||||
|
this.logger.debug("Discovered APS decision table model: {} [{}]", model.getName(), model.getId());
|
||||||
|
this.shareModel((Model) model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shareApsProcessModels() {
|
||||||
|
this.logger.trace("Discovering APS process models");
|
||||||
|
List<AbstractModel> models = this.modelService.getModelsByModelTypeAndReferenceId(Model.MODEL_TYPE_BPMN, null);
|
||||||
|
for (AbstractModel model : models) {
|
||||||
|
this.logger.debug("Discovered APS process model: {} [{}]", model.getName(), model.getId());
|
||||||
|
this.shareModel((Model) model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shareApsAppModels() {
|
||||||
|
this.logger.trace("Discovering APS app models");
|
||||||
|
List<AbstractModel> models = this.modelService.getModelsByModelTypeAndReferenceId(Model.MODEL_TYPE_APP, null);
|
||||||
|
for (AbstractModel model : models) {
|
||||||
|
this.logger.debug("Discovered APS app model: {} [{}]", model.getName(), model.getId());
|
||||||
|
this.shareModel((Model) model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shareAllActivitiModels(Long tenantId) {
|
||||||
|
this.logger.trace("Discovering activiti models in tenant {} ...", tenantId);
|
||||||
|
|
||||||
long modelCount = 0L;
|
long modelCount = 0L;
|
||||||
int page = 1;
|
int page = 1;
|
||||||
int perPage = this.modelChunkSize;
|
int perPage = this.modelChunkSize;
|
||||||
|
|
||||||
ModelQuery query = this.services.getRepositoryService().createModelQuery().latestVersion();
|
ModelQuery query = this.services.getRepositoryService().createModelQuery()
|
||||||
|
.latestVersion();
|
||||||
if (tenantId != null)
|
if (tenantId != null)
|
||||||
query.modelTenantId(String.valueOf(tenantId));
|
query.modelTenantId(String.valueOf(tenantId));
|
||||||
else query.modelWithoutTenantId();
|
else query.modelWithoutTenantId();
|
||||||
|
|
||||||
|
this.logger.trace("Discovering activiti models with page size: {}", perPage);
|
||||||
List<org.activiti.engine.repository.Model> models = query.listPage((page-1)*perPage, perPage);
|
List<org.activiti.engine.repository.Model> models = query.listPage((page-1)*perPage, perPage);
|
||||||
|
if (models.isEmpty()) {
|
||||||
|
this.logger.debug("No activiti models; procDef count: {}", this.services.getRepositoryService().createProcessDefinitionQuery().latestVersion().count());
|
||||||
|
}
|
||||||
|
|
||||||
while (!models.isEmpty()) {
|
while (!models.isEmpty()) {
|
||||||
this.logger.trace("Fetched page #{} of {} models in tenant {}", page, models.size(), this.tenantId);
|
this.logger.trace("Fetched page #{} of {} activiti models in tenant {}", page, models.size(), tenantId);
|
||||||
|
|
||||||
for (org.activiti.engine.repository.Model model : models) {
|
for (org.activiti.engine.repository.Model model : models) {
|
||||||
this.logger.debug("Discovered model: {}: {}: {}", model.getCategory(), model.getId(), model.getName());
|
this.logger.debug("Discovered model: {}: {}: {}", model.getCategory(), model.getId(), model.getName());
|
||||||
@@ -239,15 +299,19 @@ public class ModelShareWorker implements Bootstrappable {
|
|||||||
models = query.listPage((page-1)*perPage, perPage);
|
models = query.listPage((page-1)*perPage, perPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.trace("Discovered {} models in tenant {}", modelCount, this.tenantId);
|
this.logger.trace("Discovered {} activiti models in tenant {}", modelCount, tenantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shareModel(org.activiti.engine.repository.Model orgModel) {
|
public void shareModel(org.activiti.engine.repository.Model orgModel) {
|
||||||
Model model = (Model) this.modelService.getModel(Long.valueOf(orgModel.getId()));
|
Model model = (Model) this.modelService.getModel(Long.valueOf(orgModel.getId()));
|
||||||
|
this.shareModel(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shareModel(Model model) {
|
||||||
Map<HashableGroup, SharePermission> shares = this.fetchCurrentModelShares(model);
|
Map<HashableGroup, SharePermission> shares = this.fetchCurrentModelShares(model);
|
||||||
|
|
||||||
switch (model.getModelType()) {
|
switch (model.getModelType()) {
|
||||||
case 3:
|
case Model.MODEL_TYPE_APP:
|
||||||
for (Entry<HashableGroup, SharePermission> group : this.groups.entrySet()) {
|
for (Entry<HashableGroup, SharePermission> group : this.groups.entrySet()) {
|
||||||
if (this.appDefsGroups.containsKey(group.getKey())) {
|
if (this.appDefsGroups.containsKey(group.getKey())) {
|
||||||
this.logger.trace("The default group permission is overridden by the app group permission: {}", group.getKey());
|
this.logger.trace("The default group permission is overridden by the app group permission: {}", group.getKey());
|
||||||
@@ -258,7 +322,7 @@ public class ModelShareWorker implements Bootstrappable {
|
|||||||
for (Entry<HashableGroup, SharePermission> group : this.appDefsGroups.entrySet())
|
for (Entry<HashableGroup, SharePermission> group : this.appDefsGroups.entrySet())
|
||||||
this.share(shares, model, group.getKey(), group.getValue());
|
this.share(shares, model, group.getKey(), group.getValue());
|
||||||
break;
|
break;
|
||||||
case 0:
|
case Model.MODEL_TYPE_BPMN:
|
||||||
for (Entry<HashableGroup, SharePermission> group : this.groups.entrySet()) {
|
for (Entry<HashableGroup, SharePermission> group : this.groups.entrySet()) {
|
||||||
if (this.processDefsGroups.containsKey(group.getKey())) {
|
if (this.processDefsGroups.containsKey(group.getKey())) {
|
||||||
this.logger.trace("The default group permission is overridden by the app group permission: {}", group.getKey());
|
this.logger.trace("The default group permission is overridden by the app group permission: {}", group.getKey());
|
||||||
@@ -269,7 +333,7 @@ public class ModelShareWorker implements Bootstrappable {
|
|||||||
for (Entry<HashableGroup, SharePermission> group : this.processDefsGroups.entrySet())
|
for (Entry<HashableGroup, SharePermission> group : this.processDefsGroups.entrySet())
|
||||||
this.share(shares, model, group.getKey(), group.getValue());
|
this.share(shares, model, group.getKey(), group.getValue());
|
||||||
break;
|
break;
|
||||||
case 1:
|
case Model.MODEL_TYPE_FORM:
|
||||||
for (Entry<HashableGroup, SharePermission> group : this.groups.entrySet()) {
|
for (Entry<HashableGroup, SharePermission> group : this.groups.entrySet()) {
|
||||||
if (this.formDefsGroups.containsKey(group.getKey())) {
|
if (this.formDefsGroups.containsKey(group.getKey())) {
|
||||||
this.logger.trace("The default group permission is overridden by the app group permission: {}", group.getKey());
|
this.logger.trace("The default group permission is overridden by the app group permission: {}", group.getKey());
|
||||||
@@ -296,9 +360,15 @@ public class ModelShareWorker implements Bootstrappable {
|
|||||||
for (ModelShareInfo share : shares)
|
for (ModelShareInfo share : shares)
|
||||||
map.put(new HashableGroup(share.getGroup()), share.getPermission());
|
map.put(new HashableGroup(share.getGroup()), share.getPermission());
|
||||||
|
|
||||||
|
pageable = pageable.next();
|
||||||
shares = this.shareInfoRepo.findByModelIdOrderByShareDateAsc(model.getId(), pageable);
|
shares = this.shareInfoRepo.findByModelIdOrderByShareDateAsc(model.getId(), pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.logger.isTraceEnabled()) {
|
||||||
|
this.logger.trace("Found existing shares: {}", map);
|
||||||
|
} else {
|
||||||
|
this.logger.debug("Found existing shares: {}", map.size());
|
||||||
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,7 +424,13 @@ public class ModelShareWorker implements Bootstrappable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return this.group.getId().equals(((Group) obj).getId());
|
if (obj instanceof HashableGroup) {
|
||||||
|
return this.group.getId().equals(((HashableGroup) obj).getGroup().getId());
|
||||||
|
} else if (obj instanceof Group) {
|
||||||
|
return this.group.getId().equals(((Group) obj).getId());
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user