Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
14b8645f54 | |||
57e3579c37 | |||
17594dc520 | |||
adb43d46b0 | |||
a2befd7dbd | |||
b2fbe41fe1 | |||
1eb3376c80 | |||
720c83c230 | |||
d5c31527a4 | |||
b75448335e | |||
3d174119d4 | |||
32d4e807a1 | |||
0c9dff2e23 |
30
pom.xml
30
pom.xml
@@ -7,7 +7,7 @@
|
||||
|
||||
<groupId>com.inteligr8.alfresco</groupId>
|
||||
<artifactId>aps-model-maven-plugin</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.3.0</version>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
||||
<name>A Maven plugin for Alfresco Process Services model portability</name>
|
||||
@@ -34,36 +34,27 @@
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.version>3.6.3</maven.version>
|
||||
|
||||
<jersey.version>2.34</jersey.version>
|
||||
<jersey.version>2.35</jersey.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.inteligr8.alfresco</groupId>
|
||||
<artifactId>aps-public-rest-api</artifactId>
|
||||
<version>1.2.3</version>
|
||||
<version>2.0.1</version>
|
||||
<classifier>aps1</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.inteligr8.alfresco</groupId>
|
||||
<artifactId>aps-public-rest-client</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<classifier>jersey</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.ext</groupId>
|
||||
<artifactId>jersey-proxy-client</artifactId>
|
||||
<version>${jersey.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>${jersey.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
<version>${jersey.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.inject</groupId>
|
||||
<artifactId>jersey-hk2</artifactId>
|
||||
@@ -168,6 +159,9 @@
|
||||
<aps-model.authType>${aps-model.authType}</aps-model.authType>
|
||||
<aps-model.basicAuth.mavenServerId>${aps-model.basicAuth.mavenServerId}</aps-model.basicAuth.mavenServerId>
|
||||
<aps-model.appName>${aps-model.appName}</aps-model.appName>
|
||||
<aps-model.share.editors>${aps-model.share.editors}</aps-model.share.editors>
|
||||
<aps-model.share.readers>${aps-model.share.readers}</aps-model.share.readers>
|
||||
<aps-model.share.app.editors>${aps-model.share.app.editors}</aps-model.share.app.editors>
|
||||
</properties>
|
||||
</configuration>
|
||||
<executions>
|
||||
|
34
src/it/share-models/pom.xml
Normal file
34
src/it/share-models/pom.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.inteligr8.alfresco</groupId>
|
||||
<artifactId>aps-model-maven-plugin-aps-info</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>APS Share Models Plugin Tests</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>aps-model-maven-plugin</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>share-models</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>share-models</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@@ -6,11 +6,11 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.inteligr8.alfresco</groupId>
|
||||
<artifactId>aps-model-maven-plugin-deploy-app</artifactId>
|
||||
<artifactId>aps-model-maven-plugin-upload-app</artifactId>
|
||||
<version>@pom.version@</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Deploy App Plugin Tests</name>
|
||||
<name>Upload App Plugin Tests</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
@@ -53,10 +53,10 @@
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>deploy-app</id>
|
||||
<id>upload-app</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>deploy-app</goal>
|
||||
<goal>upload-app</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<zipDirectory>${project.build.directory}/aps-test</zipDirectory>
|
@@ -4,7 +4,7 @@ import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.settings.Server;
|
||||
|
||||
import com.inteligr8.alfresco.activiti.ApsClientConfiguration;
|
||||
import com.inteligr8.alfresco.activiti.ApsClientJerseyConfiguration;
|
||||
import com.inteligr8.alfresco.activiti.ApsClientJerseyImpl;
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
|
||||
|
||||
@@ -36,9 +36,9 @@ public abstract class ApsAddressibleGoal extends DisablableGoal {
|
||||
|
||||
private ApsPublicRestApiJerseyImpl api;
|
||||
|
||||
public ApsClientConfiguration getApsClientConfiguration() {
|
||||
public ApsClientJerseyConfiguration getApsClientConfiguration() {
|
||||
this.getLog().debug("Configuring APS to URL: " + this.activitiAppBaseUrl);
|
||||
ApsClientConfiguration config = new ApsClientConfiguration();
|
||||
ApsClientJerseyConfiguration config = new ApsClientJerseyConfiguration();
|
||||
config.setBaseUrl(this.activitiAppBaseUrl);
|
||||
switch (this.activitiAppAuthType.toUpperCase()) {
|
||||
case "BASIC":
|
||||
@@ -88,7 +88,7 @@ public abstract class ApsAddressibleGoal extends DisablableGoal {
|
||||
|
||||
public synchronized ApsPublicRestApiJerseyImpl getApsApi() {
|
||||
if (this.api == null) {
|
||||
ApsClientConfiguration config = this.getApsClientConfiguration();
|
||||
ApsClientJerseyConfiguration config = this.getApsClientConfiguration();
|
||||
ApsClientJerseyImpl apsClient = new ApsClientJerseyImpl(config);
|
||||
this.api = new ApsPublicRestApiJerseyImpl(apsClient);
|
||||
}
|
||||
|
@@ -42,15 +42,15 @@ public abstract class ApsAppAccessibleGoal extends ApsAddressibleGoal {
|
||||
return apps;
|
||||
}
|
||||
|
||||
protected Long findAppId() throws MojoExecutionException {
|
||||
return this.findAppIdByName(this.apsAppName);
|
||||
protected Long findAppId(boolean failOnNotFound) throws MojoExecutionException {
|
||||
return this.findAppIdByName(this.apsAppName, failOnNotFound);
|
||||
}
|
||||
|
||||
protected Long findAppIdByName(String appName) throws MojoExecutionException {
|
||||
protected Long findAppIdByName(String appName, boolean failOnNotFound) throws MojoExecutionException {
|
||||
Map<String, Long> apps = this.findAppNameIds();
|
||||
Long appId = apps.get(this.apsAppName);
|
||||
if (appId == null)
|
||||
throw new MojoExecutionException("The APS App '' could not be found; valid apps: " + apps.keySet());
|
||||
if (failOnNotFound && appId == null)
|
||||
throw new MojoExecutionException("The APS App '" + this.apsAppName + "' could not be found; valid apps: " + apps.keySet());
|
||||
return appId;
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,211 @@
|
||||
package com.inteligr8.maven.aps.modeling.goal;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
import com.inteligr8.alfresco.activiti.api.ModelsApi;
|
||||
import com.inteligr8.alfresco.activiti.model.Datum;
|
||||
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
||||
import com.inteligr8.alfresco.activiti.model.PermissionLevel;
|
||||
import com.inteligr8.alfresco.activiti.model.PermissionLight;
|
||||
import com.inteligr8.alfresco.activiti.model.ResultList;
|
||||
import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation;
|
||||
import com.inteligr8.alfresco.activiti.model.ShareInfoRequest;
|
||||
import com.inteligr8.alfresco.activiti.model.SharePermission;
|
||||
import com.inteligr8.alfresco.activiti.model.Tenant;
|
||||
import com.inteligr8.maven.aps.modeling.util.Index;
|
||||
|
||||
@Mojo( name = "share-models", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class ApsShareGoal extends ApsAddressibleGoal {
|
||||
|
||||
@Parameter( property = "aps-model.share.modelName" )
|
||||
protected String modelName;
|
||||
|
||||
@Parameter( property = "aps-model.share.readers" )
|
||||
protected String readers;
|
||||
|
||||
@Parameter( property = "aps-model.share.editors" )
|
||||
protected String editors;
|
||||
|
||||
@Parameter( property = "aps-model.share.app.readers" )
|
||||
protected String appReaders;
|
||||
|
||||
@Parameter( property = "aps-model.share.app.editors" )
|
||||
protected String appEditors;
|
||||
|
||||
@Parameter( property = "aps-model.share.process.readers" )
|
||||
protected String processReaders;
|
||||
|
||||
@Parameter( property = "aps-model.share.process.editors" )
|
||||
protected String processEditors;
|
||||
|
||||
@Parameter( property = "aps-model.share.form.readers" )
|
||||
protected String formReaders;
|
||||
|
||||
@Parameter( property = "aps-model.share.form.editors" )
|
||||
protected String formEditors;
|
||||
|
||||
@Parameter( property = "aps-model.share.doRevoke", defaultValue = "false" )
|
||||
protected boolean doRevoke = false;
|
||||
|
||||
protected Set<String> appReaderSet;
|
||||
protected Set<String> appEditorSet;
|
||||
protected Set<String> processReaderSet;
|
||||
protected Set<String> processEditorSet;
|
||||
protected Set<String> formReaderSet;
|
||||
protected Set<String> formEditorSet;
|
||||
|
||||
private Index<String, Long> identityIndex = new Index<>(128, true);
|
||||
|
||||
@Override
|
||||
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
|
||||
this.normalizeParameters();
|
||||
this.buildIdentityIndex();
|
||||
|
||||
if (!this.appReaderSet.isEmpty() || !this.appEditorSet.isEmpty())
|
||||
this.shareModels(ModelsApi.ModelType.App, this.appReaderSet, this.appEditorSet);
|
||||
|
||||
if (!this.processReaderSet.isEmpty() || !this.processEditorSet.isEmpty())
|
||||
this.shareModels(ModelsApi.ModelType.Process, this.processReaderSet, this.processEditorSet);
|
||||
|
||||
if (!this.formReaderSet.isEmpty() || !this.formEditorSet.isEmpty())
|
||||
this.shareModels(ModelsApi.ModelType.Form, this.formReaderSet, this.formEditorSet);
|
||||
}
|
||||
|
||||
private void shareModels(ModelsApi.ModelType modelType, Set<String> readers, Set<String> editors) {
|
||||
ResultListDataRepresentation models = this.getApsApi().getModelsApi().get(null, null, modelType.getId(), null);
|
||||
if (models.getData() == null)
|
||||
return;
|
||||
|
||||
for (Datum datum : models.getData()) {
|
||||
Number modelId = (Number)datum.getAdditionalProperties().get("id");
|
||||
String modelName = (String)datum.getAdditionalProperties().get("name");
|
||||
if (this.modelName != null && !this.modelName.equals(modelName))
|
||||
continue;
|
||||
|
||||
Set<String> groupsAddressed = new HashSet<>();
|
||||
Set<String> readersUnaddressed = new HashSet<>(readers);
|
||||
Set<String> editorsUnaddressed = new HashSet<>(editors);
|
||||
ShareInfoRequest changeRequest = new ShareInfoRequest();
|
||||
|
||||
ResultList<SharePermission> shares = this.getApsApi().getShareApi().getShareInfo(modelId.toString());
|
||||
if (shares.getData() != null) {
|
||||
for (SharePermission share : shares.getData()) {
|
||||
if (share.getGroup() != null) {
|
||||
groupsAddressed.add(share.getGroup().getName());
|
||||
this.analyzeChanges(modelName, readers, editors, share, changeRequest);
|
||||
} else if (share.getPerson() != null) {
|
||||
this.getLog().debug("Person-based model sharing not supported at this time; ignoring");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
readersUnaddressed.removeAll(groupsAddressed);
|
||||
for (String reader : readersUnaddressed)
|
||||
this.analyzeChanges(modelName, reader, PermissionLevel.Read, changeRequest);
|
||||
|
||||
editorsUnaddressed.removeAll(groupsAddressed);
|
||||
for (String editor : editorsUnaddressed)
|
||||
this.analyzeChanges(modelName, editor, PermissionLevel.Write, changeRequest);
|
||||
|
||||
if (!changeRequest.getAdded().isEmpty() || !changeRequest.getUpdated().isEmpty() || !changeRequest.getRemoved().isEmpty()) {
|
||||
this.getLog().info("Sharing model: " + modelType + " => '" + modelName + "'");
|
||||
this.getApsApi().getShareApi().setShareInfo(modelId.toString(), changeRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void analyzeChanges(String modelName, Set<String> readers, Set<String> editors, SharePermission share, ShareInfoRequest changeRequest) {
|
||||
if (PermissionLevel.Write.equals(share.getPermission())) {
|
||||
if (editors.contains(share.getGroup().getName())) {
|
||||
this.getLog().debug("The named group '" + share.getGroup().getName() + "' is already an editor of model '" + modelName + "'");
|
||||
// no change
|
||||
return;
|
||||
} else if (readers.contains(share.getGroup().getName())) {
|
||||
this.getLog().debug("The named group '" + share.getGroup().getName() + "' reverting from editor to reader of model '" + modelName + "'");
|
||||
changeRequest.getUpdated().add(new PermissionLight().withId(share.getId()).withPermission(PermissionLevel.Read));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (editors.contains(share.getGroup().getName())) {
|
||||
this.getLog().debug("The named group '" + share.getGroup().getName() + "' elevating from reader to editor of model '" + modelName + "'");
|
||||
changeRequest.getUpdated().add(new PermissionLight().withId(share.getId()).withPermission(PermissionLevel.Write));
|
||||
return;
|
||||
} else if (readers.contains(share.getGroup().getName())) {
|
||||
this.getLog().debug("The named group '" + share.getGroup().getName() + "' is already an reader of model '" + modelName + "'");
|
||||
// no change
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.doRevoke) {
|
||||
this.getLog().debug("The named group '" + share.getGroup().getName() + "' is an unregulated editor of model '" + modelName + "'; revoking ...");
|
||||
changeRequest.getRemoved().add(new PermissionLight().withId(share.getId()));
|
||||
} else {
|
||||
this.getLog().debug("The named group '" + share.getGroup().getName() + "' is an unregulated editor of model '" + modelName + "'");
|
||||
// not touching extra unnamed permissions
|
||||
}
|
||||
}
|
||||
|
||||
private void analyzeChanges(String modelName, String groupName, PermissionLevel plevel, ShareInfoRequest changeRequest) {
|
||||
Long groupId = this.identityIndex.getValue(groupName);
|
||||
if (groupId == null) {
|
||||
this.getLog().warn("The named group '" + groupName + "' does not exist in APS; ignoring ...");
|
||||
} else {
|
||||
this.getLog().debug("The named group '" + groupName + "' granted the " + plevel + " role of model '" + modelName + "'");
|
||||
changeRequest.getAdded().add(new PermissionLight().withGroupId(groupId).withPermission(plevel));
|
||||
}
|
||||
}
|
||||
|
||||
protected void normalizeParameters() {
|
||||
Set<String> readerSet = this.normalizeParameter(this.readers);
|
||||
Set<String> editorSet = this.normalizeParameter(this.editors);
|
||||
this.appReaderSet = this.normalizeParameter(this.appReaders, readerSet);
|
||||
this.appEditorSet = this.normalizeParameter(this.appEditors, editorSet);
|
||||
this.processReaderSet = this.normalizeParameter(this.processReaders, readerSet);
|
||||
this.processEditorSet = this.normalizeParameter(this.processEditors, editorSet);
|
||||
this.formReaderSet = this.normalizeParameter(this.formReaders, readerSet);
|
||||
this.formEditorSet = this.normalizeParameter(this.formEditors, editorSet);
|
||||
}
|
||||
|
||||
private Set<String> normalizeParameter(String parameter, Collection<String> c) {
|
||||
Set<String> set = this.normalizeParameter(parameter);
|
||||
set.addAll(c);
|
||||
return set;
|
||||
}
|
||||
|
||||
private Set<String> normalizeParameter(String parameter) {
|
||||
Set<String> params = new HashSet<>();
|
||||
if (parameter == null)
|
||||
return params;
|
||||
if (parameter.length() == 0)
|
||||
return params;
|
||||
|
||||
String[] splitParams = parameter.split(",");
|
||||
params.addAll(Arrays.asList(splitParams));
|
||||
return params;
|
||||
}
|
||||
|
||||
protected void buildIdentityIndex() {
|
||||
List<Tenant> tenants = this.getApsApi().getAdminApi().getTenants();
|
||||
for (Tenant tenant : tenants) {
|
||||
List<GroupLight> groups = this.getApsApi().getAdminApi().getGroups(tenant.getId(), true, true);
|
||||
this.getLog().debug("Indexing groups: " + groups.size());
|
||||
for (GroupLight group : groups)
|
||||
this.identityIndex.put(group.getName(), group.getId());
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("Indexed groups: " + this.identityIndex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -23,7 +23,7 @@ public class DownloadAppGoal extends ApsAppAccessibleGoal {
|
||||
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
|
||||
this.validateTargetDirectory();
|
||||
|
||||
Long appId = this.findAppId();
|
||||
Long appId = this.findAppId(true);
|
||||
File appZip = this.downloadApp(appId);
|
||||
|
||||
File toAppZip = new File(this.zipDirectory, this.apsAppName + ".zip");
|
||||
|
@@ -0,0 +1,40 @@
|
||||
package com.inteligr8.maven.aps.modeling.goal;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
|
||||
import com.inteligr8.alfresco.activiti.model.AppDefinitionPublishRepresentation;
|
||||
|
||||
@Mojo( name = "publish-app", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class PublishAppGoal extends ApsAppAccessibleGoal {
|
||||
|
||||
@Parameter( property = "aps-model.publish.comment", required = true, defaultValue = "Automated by 'aps-model-maven-plugin'" )
|
||||
protected String comment;
|
||||
|
||||
@Override
|
||||
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
|
||||
Long appId = this.findAppId(false);
|
||||
|
||||
try {
|
||||
this.publishApp(appId);
|
||||
} catch (IOException ie) {
|
||||
throw new MojoExecutionException("The APS App could not be published", ie);
|
||||
}
|
||||
}
|
||||
|
||||
private void publishApp(Long appId) throws IOException, MojoExecutionException {
|
||||
ApsPublicRestApiJerseyImpl api = this.getApsApi();
|
||||
|
||||
AppDefinitionPublishRepresentation appDefPublish = new AppDefinitionPublishRepresentation();
|
||||
appDefPublish.setComment(this.comment);
|
||||
api.getAppDefinitionsApi().publish(appId, appDefPublish);
|
||||
}
|
||||
|
||||
}
|
@@ -16,9 +16,9 @@ import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
|
||||
import com.inteligr8.alfresco.activiti.model.AppDefinitionUpdateResultRepresentation;
|
||||
import com.inteligr8.alfresco.activiti.model.FileMultipartJersey;
|
||||
|
||||
@Mojo( name = "deploy-app", threadSafe = true )
|
||||
@Mojo( name = "upload-app", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class DeployAppGoal extends ApsAppAccessibleGoal {
|
||||
public class UploadAppGoal extends ApsAppAccessibleGoal {
|
||||
|
||||
@Parameter( property = "aps-model.upload.directory", required = true, defaultValue = "${project.build.directory}/aps" )
|
||||
protected File zipDirectory;
|
||||
@@ -32,7 +32,7 @@ public class DeployAppGoal extends ApsAppAccessibleGoal {
|
||||
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
|
||||
File sourceFile = this.validateSourceDirectory();
|
||||
|
||||
Long appId = this.findAppId();
|
||||
Long appId = this.findAppId(false);
|
||||
|
||||
try {
|
||||
this.uploadApp(appId, sourceFile);
|
@@ -9,25 +9,26 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.inteligr8.alfresco.activiti.model.Group;
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
||||
import com.inteligr8.maven.aps.modeling.util.Index;
|
||||
import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
||||
|
||||
public class ApsAppJsonTranslator implements ApsFileTranslator {
|
||||
public class ApsAppJsonTranslator extends ApsOrganizationHandler implements ApsFileTranslator {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ApsAppJsonTranslator.class);
|
||||
|
||||
private Map<String, Group> apsOrgIndex;
|
||||
private Index<Long, String> apsProcessIndex;
|
||||
private Index<Long, String> fileProcessIndex;
|
||||
private final Map<String, GroupLight> apsOrgIndex;
|
||||
private final Index<Long, String> apsProcessIndex;
|
||||
private final Index<Long, String> fileProcessIndex;
|
||||
|
||||
public ApsAppJsonTranslator(
|
||||
Map<String, Group> apsOrgIndex,
|
||||
ApsPublicRestApi api,
|
||||
Map<String, GroupLight> apsOrgIndex,
|
||||
Index<Long, String> apsProcessIndex,
|
||||
Index<Long, String> fileProcessIndex) {
|
||||
super(api, apsOrgIndex);
|
||||
this.apsOrgIndex = apsOrgIndex;
|
||||
this.apsProcessIndex = apsProcessIndex;
|
||||
|
||||
this.fileProcessIndex = fileProcessIndex;
|
||||
}
|
||||
|
||||
@@ -84,11 +85,16 @@ public class ApsAppJsonTranslator implements ApsFileTranslator {
|
||||
|
||||
if (this.apsOrgIndex.containsKey(fileOrgName)) {
|
||||
long fileOrgId = jsonGroup.get("id").asLong();
|
||||
long apsOrgId = this.apsOrgIndex.get(fileOrgName).getId();
|
||||
GroupLight apsOrg = this.apsOrgIndex.get(fileOrgName);
|
||||
|
||||
if (fileOrgId != apsOrgId) {
|
||||
this.logger.debug("The organization '{}' exists in APS with ID {}; changing descriptor", fileOrgName, apsOrgId);
|
||||
jsonGroup.put("id", apsOrgId);
|
||||
if (apsOrg == null) {
|
||||
this.logger.debug("The organization '{}' does not exist in APS; adding to APS", fileOrgName);
|
||||
long apsGroupId = this.createOrganization(fileOrgName);
|
||||
jsonGroup.put("id", apsGroupId);
|
||||
changed = true;
|
||||
} else if (fileOrgId != apsOrg.getId()) {
|
||||
this.logger.debug("The organization '{}' exists in APS with ID {}; changing descriptor", fileOrgName, apsOrg.getId());
|
||||
jsonGroup.put("id", apsOrg.getId());
|
||||
changed = true;
|
||||
} else {
|
||||
this.logger.trace("The organization '{}' ID does not change; leaving unchanged", fileOrgName);
|
||||
|
@@ -16,7 +16,7 @@ import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
|
||||
import com.inteligr8.alfresco.activiti.api.ModelsApi.ModelType;
|
||||
import com.inteligr8.alfresco.activiti.model.Datum;
|
||||
import com.inteligr8.alfresco.activiti.model.Group;
|
||||
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
||||
import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation;
|
||||
import com.inteligr8.alfresco.activiti.model.Tenant;
|
||||
import com.inteligr8.maven.aps.modeling.crawler.ApsAppCrawlable;
|
||||
@@ -31,7 +31,7 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
||||
private final File appDirectory;
|
||||
|
||||
private boolean indexesBuilt = false;
|
||||
private Map<String, Group> apsOrgIndex;
|
||||
private Map<String, GroupLight> apsOrgIndex;
|
||||
private Index<Long, String> apsFormIndex;
|
||||
private Index<Long, String> apsProcessIndex;
|
||||
private Index<Long, String> fileFormIndex;
|
||||
@@ -95,6 +95,7 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
||||
throw new IllegalStateException("The indexes are never built");
|
||||
|
||||
return new ApsAppJsonTranslator(
|
||||
this.api,
|
||||
this.apsOrgIndex,
|
||||
this.apsProcessIndex,
|
||||
this.fileProcessIndex);
|
||||
@@ -115,6 +116,7 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
||||
throw new IllegalStateException("The indexes are never built");
|
||||
|
||||
return new ApsProcessJsonTranslator(
|
||||
this.api,
|
||||
this.apsProcessIndex,
|
||||
this.apsOrgIndex,
|
||||
this.apsFormIndex);
|
||||
@@ -126,6 +128,7 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
||||
throw new IllegalStateException("The indexes are never built");
|
||||
|
||||
return new ApsProcessBpmnTranslator(
|
||||
this.api,
|
||||
this.apsProcessIndex,
|
||||
this.apsOrgIndex,
|
||||
this.apsFormIndex,
|
||||
@@ -137,11 +140,11 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
||||
return (tenants == null || tenants.isEmpty()) ? null : tenants.iterator().next().getId();
|
||||
}
|
||||
|
||||
protected Map<String, Group> buildApsGroupMap(long tenantId) {
|
||||
List<Group> groups = this.api.getAdminApi().getGroups(tenantId, true, true);
|
||||
protected Map<String, GroupLight> buildApsGroupMap(long tenantId) {
|
||||
List<GroupLight> groups = this.api.getAdminApi().getGroups(tenantId, true, true);
|
||||
|
||||
Map<String, Group> map = new HashMap<>(groups.size());
|
||||
for (Group group : groups)
|
||||
Map<String, GroupLight> map = new HashMap<>(groups.size());
|
||||
for (GroupLight group : groups)
|
||||
map.put(group.getName(), group);
|
||||
return map;
|
||||
}
|
||||
|
@@ -0,0 +1,35 @@
|
||||
package com.inteligr8.maven.aps.modeling.translator;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||
import com.inteligr8.alfresco.activiti.model.Group;
|
||||
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
||||
|
||||
public class ApsOrganizationHandler {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ApsOrganizationHandler.class);
|
||||
private final ApsPublicRestApi api;
|
||||
private final Map<String, GroupLight> apsOrgIndex;
|
||||
|
||||
public ApsOrganizationHandler(
|
||||
ApsPublicRestApi api,
|
||||
Map<String, GroupLight> apsOrgIndex) {
|
||||
this.api = api;
|
||||
this.apsOrgIndex = apsOrgIndex;
|
||||
}
|
||||
|
||||
protected long createOrganization(String groupName) {
|
||||
this.logger.info("Creating organization '{}' in APS", groupName);
|
||||
|
||||
GroupLight group = this.api.getAdminApi().createGroup(new Group()
|
||||
.withName(groupName)
|
||||
.withType(1L)); // an organization, not capability
|
||||
this.apsOrgIndex.put(groupName, group);
|
||||
return group.getId();
|
||||
}
|
||||
|
||||
}
|
@@ -22,30 +22,32 @@ import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.inteligr8.alfresco.activiti.model.Group;
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
||||
import com.inteligr8.maven.aps.modeling.util.Index;
|
||||
import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
||||
|
||||
public class ApsProcessBpmnTranslator implements ApsFileTranslator {
|
||||
public class ApsProcessBpmnTranslator extends ApsOrganizationHandler implements ApsFileTranslator {
|
||||
|
||||
private static final String NAMESPACE_ACTIVITI = "http://activiti.org/bpmn";
|
||||
private static final String NAMESPACE_ACTIVITI_MODELER = "http://activiti.com/modeler";
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ApsProcessBpmnTranslator.class);
|
||||
private final Index<Long, String> apsIndex;
|
||||
private final Map<String, Group> apsOrgIndex;
|
||||
private final Map<String, GroupLight> apsOrgIndex;
|
||||
private final Index<Long, String> apsFormIndex;
|
||||
private final Index<Long, String> fileFormIndex;
|
||||
|
||||
public ApsProcessBpmnTranslator(
|
||||
ApsPublicRestApi api,
|
||||
Index<Long, String> apsProcessIndex,
|
||||
Map<String, Group> apsOrgIndex,
|
||||
Map<String, GroupLight> apsOrgIndex,
|
||||
Index<Long, String> apsFormIndex,
|
||||
Index<Long, String> fileFormIndex) {
|
||||
super(api, apsOrgIndex);
|
||||
this.apsIndex = apsProcessIndex;
|
||||
this.apsOrgIndex = apsOrgIndex;
|
||||
this.apsFormIndex = apsFormIndex;
|
||||
|
||||
this.fileFormIndex = fileFormIndex;
|
||||
}
|
||||
|
||||
@@ -141,22 +143,26 @@ public class ApsProcessBpmnTranslator implements ApsFileTranslator {
|
||||
String groupName = groupNameElement.getTextContent().trim();
|
||||
this.logger.trace("Found '{}' candidate group in the APS Process BPMN model", groupName);
|
||||
|
||||
if (this.apsOrgIndex.containsKey(groupName)) {
|
||||
long apsOrgId = this.apsOrgIndex.get(groupName).getId();
|
||||
groupIdsList.add(apsOrgId);
|
||||
|
||||
if (apsOrgId != orgId) {
|
||||
this.logger.debug("The organization '{}' exists in APS with ID {}; changing model", groupName, apsOrgId);
|
||||
groupNameElement = (Element)groupNameElement.getOwnerDocument().renameNode(groupNameElement,
|
||||
groupNameElement.getNamespaceURI(), "modeler:group-info-name-" + apsOrgId);
|
||||
changed = true;
|
||||
} else {
|
||||
this.logger.trace("The organization '{}' ID does not change; leaving unchanged", groupName);
|
||||
}
|
||||
GroupLight apsOrg = this.apsOrgIndex.get(groupName);
|
||||
long apsOrgId = 0L;
|
||||
if (apsOrg == null) {
|
||||
this.logger.debug("The organization '{}' does not exist in APS; creating it ...", groupName);
|
||||
apsOrgId = this.createOrganization(groupName);
|
||||
} else {
|
||||
// FIXME automatically add the group?
|
||||
this.logger.debug("The organization '{}' does not exist in APS; leaving unchanged", groupName);
|
||||
groupIdsList.add(orgId);
|
||||
apsOrgId = apsOrg.getId();
|
||||
}
|
||||
|
||||
if (apsOrgId != orgId) {
|
||||
this.logger.debug("The organization '{}' exists in APS with ID {}; changing model", groupName, apsOrgId);
|
||||
groupNameElement = (Element)groupNameElement.getOwnerDocument().renameNode(groupNameElement,
|
||||
groupNameElement.getNamespaceURI(), "modeler:group-info-name-" + apsOrgId);
|
||||
|
||||
groupIdsList.add(apsOrgId);
|
||||
changed = true;
|
||||
} else {
|
||||
this.logger.trace("The organization '{}' ID does not change; leaving unchanged", groupName);
|
||||
|
||||
groupIdsList.add(apsOrgId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -10,21 +10,24 @@ import org.slf4j.LoggerFactory;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.inteligr8.alfresco.activiti.model.Group;
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
||||
import com.inteligr8.maven.aps.modeling.util.Index;
|
||||
import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
||||
|
||||
public class ApsProcessJsonTranslator implements ApsFileTranslator {
|
||||
public class ApsProcessJsonTranslator extends ApsOrganizationHandler implements ApsFileTranslator {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ApsProcessJsonTranslator.class);
|
||||
private final Index<Long, String> apsIndex;
|
||||
private final Map<String, Group> apsOrgIndex;
|
||||
private final Map<String, GroupLight> apsOrgIndex;
|
||||
private final Index<Long, String> apsFormIndex;
|
||||
|
||||
public ApsProcessJsonTranslator(
|
||||
ApsPublicRestApi api,
|
||||
Index<Long, String> apsProcessIndex,
|
||||
Map<String, Group> apsOrgIndex,
|
||||
Map<String, GroupLight> apsOrgIndex,
|
||||
Index<Long, String> apsFormIndex) {
|
||||
super(api, apsOrgIndex);
|
||||
this.apsIndex = apsProcessIndex;
|
||||
this.apsOrgIndex = apsOrgIndex;
|
||||
this.apsFormIndex = apsFormIndex;
|
||||
@@ -107,10 +110,16 @@ public class ApsProcessJsonTranslator implements ApsFileTranslator {
|
||||
|
||||
if (this.apsOrgIndex.containsKey(fileOrgName)) {
|
||||
long fileOrgId = jsonCandidateGroup.get("id").asLong();
|
||||
long apsOrgId = this.apsOrgIndex.get(fileOrgName).getId();
|
||||
if (apsOrgId != fileOrgId) {
|
||||
this.logger.debug("The organization '{}' exists in APS with ID {}; changing descriptor", fileOrgName, apsOrgId);
|
||||
jsonCandidateGroup.put("id", apsOrgId);
|
||||
GroupLight apsOrg = this.apsOrgIndex.get(fileOrgName);
|
||||
|
||||
if (apsOrg == null) {
|
||||
this.logger.debug("The organization '{}' does not exist in APS; adding to APS", fileOrgName);
|
||||
long apsGroupId = this.createOrganization(fileOrgName);
|
||||
jsonCandidateGroup.put("id", apsGroupId);
|
||||
return true;
|
||||
} else if (apsOrg.getId() != fileOrgId) {
|
||||
this.logger.debug("The organization '{}' exists in APS with ID {}; changing descriptor", fileOrgName, apsOrg.getId());
|
||||
jsonCandidateGroup.put("id", apsOrg.getId());
|
||||
return true;
|
||||
} else {
|
||||
this.logger.trace("The organization '{}' ID does not change; leaving unchanged", fileOrgName);
|
||||
|
Reference in New Issue
Block a user