automatically adding missing organizations
This commit is contained in:
parent
0c9dff2e23
commit
32d4e807a1
@ -9,25 +9,26 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||||
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
||||||
import com.inteligr8.maven.aps.modeling.util.Index;
|
import com.inteligr8.maven.aps.modeling.util.Index;
|
||||||
import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
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 final Logger logger = LoggerFactory.getLogger(ApsAppJsonTranslator.class);
|
||||||
|
private final Map<String, GroupLight> apsOrgIndex;
|
||||||
private Map<String, GroupLight> apsOrgIndex;
|
private final Index<Long, String> apsProcessIndex;
|
||||||
private Index<Long, String> apsProcessIndex;
|
private final Index<Long, String> fileProcessIndex;
|
||||||
private Index<Long, String> fileProcessIndex;
|
|
||||||
|
|
||||||
public ApsAppJsonTranslator(
|
public ApsAppJsonTranslator(
|
||||||
|
ApsPublicRestApi api,
|
||||||
Map<String, GroupLight> apsOrgIndex,
|
Map<String, GroupLight> apsOrgIndex,
|
||||||
Index<Long, String> apsProcessIndex,
|
Index<Long, String> apsProcessIndex,
|
||||||
Index<Long, String> fileProcessIndex) {
|
Index<Long, String> fileProcessIndex) {
|
||||||
|
super(api, apsOrgIndex);
|
||||||
this.apsOrgIndex = apsOrgIndex;
|
this.apsOrgIndex = apsOrgIndex;
|
||||||
this.apsProcessIndex = apsProcessIndex;
|
this.apsProcessIndex = apsProcessIndex;
|
||||||
|
|
||||||
this.fileProcessIndex = fileProcessIndex;
|
this.fileProcessIndex = fileProcessIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,11 +85,16 @@ public class ApsAppJsonTranslator implements ApsFileTranslator {
|
|||||||
|
|
||||||
if (this.apsOrgIndex.containsKey(fileOrgName)) {
|
if (this.apsOrgIndex.containsKey(fileOrgName)) {
|
||||||
long fileOrgId = jsonGroup.get("id").asLong();
|
long fileOrgId = jsonGroup.get("id").asLong();
|
||||||
long apsOrgId = this.apsOrgIndex.get(fileOrgName).getId();
|
GroupLight apsOrg = this.apsOrgIndex.get(fileOrgName);
|
||||||
|
|
||||||
if (fileOrgId != apsOrgId) {
|
if (apsOrg == null) {
|
||||||
this.logger.debug("The organization '{}' exists in APS with ID {}; changing descriptor", fileOrgName, apsOrgId);
|
this.logger.debug("The organization '{}' does not exist in APS; adding to APS", fileOrgName);
|
||||||
jsonGroup.put("id", apsOrgId);
|
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;
|
changed = true;
|
||||||
} else {
|
} else {
|
||||||
this.logger.trace("The organization '{}' ID does not change; leaving unchanged", fileOrgName);
|
this.logger.trace("The organization '{}' ID does not change; leaving unchanged", fileOrgName);
|
||||||
|
@ -95,6 +95,7 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
|||||||
throw new IllegalStateException("The indexes are never built");
|
throw new IllegalStateException("The indexes are never built");
|
||||||
|
|
||||||
return new ApsAppJsonTranslator(
|
return new ApsAppJsonTranslator(
|
||||||
|
this.api,
|
||||||
this.apsOrgIndex,
|
this.apsOrgIndex,
|
||||||
this.apsProcessIndex,
|
this.apsProcessIndex,
|
||||||
this.fileProcessIndex);
|
this.fileProcessIndex);
|
||||||
@ -115,6 +116,7 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
|||||||
throw new IllegalStateException("The indexes are never built");
|
throw new IllegalStateException("The indexes are never built");
|
||||||
|
|
||||||
return new ApsProcessJsonTranslator(
|
return new ApsProcessJsonTranslator(
|
||||||
|
this.api,
|
||||||
this.apsProcessIndex,
|
this.apsProcessIndex,
|
||||||
this.apsOrgIndex,
|
this.apsOrgIndex,
|
||||||
this.apsFormIndex);
|
this.apsFormIndex);
|
||||||
@ -126,6 +128,7 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
|||||||
throw new IllegalStateException("The indexes are never built");
|
throw new IllegalStateException("The indexes are never built");
|
||||||
|
|
||||||
return new ApsProcessBpmnTranslator(
|
return new ApsProcessBpmnTranslator(
|
||||||
|
this.api,
|
||||||
this.apsProcessIndex,
|
this.apsProcessIndex,
|
||||||
this.apsOrgIndex,
|
this.apsOrgIndex,
|
||||||
this.apsFormIndex,
|
this.apsFormIndex,
|
||||||
|
@ -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,11 +22,12 @@ import org.w3c.dom.Element;
|
|||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||||
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
||||||
import com.inteligr8.maven.aps.modeling.util.Index;
|
import com.inteligr8.maven.aps.modeling.util.Index;
|
||||||
import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
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 = "http://activiti.org/bpmn";
|
||||||
private static final String NAMESPACE_ACTIVITI_MODELER = "http://activiti.com/modeler";
|
private static final String NAMESPACE_ACTIVITI_MODELER = "http://activiti.com/modeler";
|
||||||
@ -38,14 +39,15 @@ public class ApsProcessBpmnTranslator implements ApsFileTranslator {
|
|||||||
private final Index<Long, String> fileFormIndex;
|
private final Index<Long, String> fileFormIndex;
|
||||||
|
|
||||||
public ApsProcessBpmnTranslator(
|
public ApsProcessBpmnTranslator(
|
||||||
|
ApsPublicRestApi api,
|
||||||
Index<Long, String> apsProcessIndex,
|
Index<Long, String> apsProcessIndex,
|
||||||
Map<String, GroupLight> apsOrgIndex,
|
Map<String, GroupLight> apsOrgIndex,
|
||||||
Index<Long, String> apsFormIndex,
|
Index<Long, String> apsFormIndex,
|
||||||
Index<Long, String> fileFormIndex) {
|
Index<Long, String> fileFormIndex) {
|
||||||
|
super(api, apsOrgIndex);
|
||||||
this.apsIndex = apsProcessIndex;
|
this.apsIndex = apsProcessIndex;
|
||||||
this.apsOrgIndex = apsOrgIndex;
|
this.apsOrgIndex = apsOrgIndex;
|
||||||
this.apsFormIndex = apsFormIndex;
|
this.apsFormIndex = apsFormIndex;
|
||||||
|
|
||||||
this.fileFormIndex = fileFormIndex;
|
this.fileFormIndex = fileFormIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,22 +143,26 @@ public class ApsProcessBpmnTranslator implements ApsFileTranslator {
|
|||||||
String groupName = groupNameElement.getTextContent().trim();
|
String groupName = groupNameElement.getTextContent().trim();
|
||||||
this.logger.trace("Found '{}' candidate group in the APS Process BPMN model", groupName);
|
this.logger.trace("Found '{}' candidate group in the APS Process BPMN model", groupName);
|
||||||
|
|
||||||
if (this.apsOrgIndex.containsKey(groupName)) {
|
GroupLight apsOrg = this.apsOrgIndex.get(groupName);
|
||||||
long apsOrgId = this.apsOrgIndex.get(groupName).getId();
|
long apsOrgId = 0L;
|
||||||
groupIdsList.add(apsOrgId);
|
if (apsOrg == null) {
|
||||||
|
this.logger.debug("The organization '{}' does not exist in APS; creating it ...", groupName);
|
||||||
if (apsOrgId != orgId) {
|
apsOrgId = this.createOrganization(groupName);
|
||||||
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);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// FIXME automatically add the group?
|
apsOrgId = apsOrg.getId();
|
||||||
this.logger.debug("The organization '{}' does not exist in APS; leaving unchanged", groupName);
|
}
|
||||||
groupIdsList.add(orgId);
|
|
||||||
|
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,11 +10,12 @@ import org.slf4j.LoggerFactory;
|
|||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||||
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
||||||
import com.inteligr8.maven.aps.modeling.util.Index;
|
import com.inteligr8.maven.aps.modeling.util.Index;
|
||||||
import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
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 Logger logger = LoggerFactory.getLogger(ApsProcessJsonTranslator.class);
|
||||||
private final Index<Long, String> apsIndex;
|
private final Index<Long, String> apsIndex;
|
||||||
@ -22,9 +23,11 @@ public class ApsProcessJsonTranslator implements ApsFileTranslator {
|
|||||||
private final Index<Long, String> apsFormIndex;
|
private final Index<Long, String> apsFormIndex;
|
||||||
|
|
||||||
public ApsProcessJsonTranslator(
|
public ApsProcessJsonTranslator(
|
||||||
|
ApsPublicRestApi api,
|
||||||
Index<Long, String> apsProcessIndex,
|
Index<Long, String> apsProcessIndex,
|
||||||
Map<String, GroupLight> apsOrgIndex,
|
Map<String, GroupLight> apsOrgIndex,
|
||||||
Index<Long, String> apsFormIndex) {
|
Index<Long, String> apsFormIndex) {
|
||||||
|
super(api, apsOrgIndex);
|
||||||
this.apsIndex = apsProcessIndex;
|
this.apsIndex = apsProcessIndex;
|
||||||
this.apsOrgIndex = apsOrgIndex;
|
this.apsOrgIndex = apsOrgIndex;
|
||||||
this.apsFormIndex = apsFormIndex;
|
this.apsFormIndex = apsFormIndex;
|
||||||
@ -107,10 +110,16 @@ public class ApsProcessJsonTranslator implements ApsFileTranslator {
|
|||||||
|
|
||||||
if (this.apsOrgIndex.containsKey(fileOrgName)) {
|
if (this.apsOrgIndex.containsKey(fileOrgName)) {
|
||||||
long fileOrgId = jsonCandidateGroup.get("id").asLong();
|
long fileOrgId = jsonCandidateGroup.get("id").asLong();
|
||||||
long apsOrgId = this.apsOrgIndex.get(fileOrgName).getId();
|
GroupLight apsOrg = this.apsOrgIndex.get(fileOrgName);
|
||||||
if (apsOrgId != fileOrgId) {
|
|
||||||
this.logger.debug("The organization '{}' exists in APS with ID {}; changing descriptor", fileOrgName, apsOrgId);
|
if (apsOrg == null) {
|
||||||
jsonCandidateGroup.put("id", apsOrgId);
|
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;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
this.logger.trace("The organization '{}' ID does not change; leaving unchanged", fileOrgName);
|
this.logger.trace("The organization '{}' ID does not change; leaving unchanged", fileOrgName);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user