diff --git a/pom.xml b/pom.xml index fd39c9a..2131626 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ com.inteligr8.alfresco aps-public-rest-api - 2.0.15 + 2.0.16 com.inteligr8.alfresco diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAddressibleGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAddressibleGoal.java index ae22f7d..e566256 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAddressibleGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAddressibleGoal.java @@ -22,8 +22,10 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; import com.inteligr8.activiti.model.Datum; +import com.inteligr8.activiti.model.ResultList; import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl; import com.inteligr8.alfresco.activiti.api.ModelsApi.ModelType; +import com.inteligr8.alfresco.activiti.model.ModelRepresentation; import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation; import com.inteligr8.alfresco.activiti.model.Tenant; @@ -58,24 +60,23 @@ public abstract class ApsAppAddressibleGoal extends ApsAddressibleGoal { /** * This method makes the appropriate service calls to find all the APS - * Apps, returning them as a map of names to IDs. + * Apps, returning them as a map of names to models. * * This method does not cache the result. * - * @return A map of APS App names to their respective IDs; may be empty; never null. + * @return A map of APS App names to their model; may be empty; never null. */ - protected Map findAppNameIds() { + protected Map buildAppNameMap() { ApsPublicRestApiJerseyImpl api = this.getApsApi(); - Map apps = new HashMap<>(16); + Map apps = new HashMap<>(16); this.getLog().debug("Searching for all APS Apps"); - ResultListDataRepresentation results = api.getModelsApi().get("everyone", null, ModelType.App.getId(), null); + ResultList results = api.getModelsApi().get("everyone", null, ModelType.App.getId(), null); this.getLog().debug("Found " + results.getTotal() + " APS Apps"); - for (Datum datum : results.getData()) { - String name = (String)datum.getAdditionalProperties().get("name"); - Number id = (Number)datum.getAdditionalProperties().get("id"); - apps.put(name, id.longValue()); + for (ModelRepresentation model : results.getData()) { + String name = model.getName(); + apps.put(name, model); } return apps; @@ -88,11 +89,11 @@ public abstract class ApsAppAddressibleGoal extends ApsAddressibleGoal { * This method does not cache the result. * * @param failOnNotFound true to fail if not found; false to return null. - * @return An APS App ID; null if not found. + * @return An APS App model; null if not found. * @throws MojoExecutionException The APS App could not be found. */ - protected Long findAppId(boolean failOnNotFound) throws MojoExecutionException { - return this.findAppIdByName(this.apsAppName, failOnNotFound); + protected ModelRepresentation findAppModel(boolean failOnNotFound) throws MojoExecutionException { + return this.findAppModelByName(this.apsAppName, failOnNotFound); } /** @@ -103,15 +104,15 @@ public abstract class ApsAppAddressibleGoal extends ApsAddressibleGoal { * * @param apsName An APS App name. * @param failOnNotFound true to fail if not found; false to return null. - * @return An APS App ID; null if not found. + * @return An APS App model; null if not found. * @throws MojoExecutionException The APS App could not be found. */ - protected Long findAppIdByName(String appName, boolean failOnNotFound) throws MojoExecutionException { - Map apps = this.findAppNameIds(); - Long appId = apps.get(this.apsAppName); - if (failOnNotFound && appId == null) + protected ModelRepresentation findAppModelByName(String appName, boolean failOnNotFound) throws MojoExecutionException { + Map apps = this.buildAppNameMap(); + ModelRepresentation appModel = apps.get(this.apsAppName); + if (failOnNotFound && appModel == null) throw new MojoExecutionException("The APS App '" + this.apsAppName + "' could not be found; valid apps: " + apps.keySet()); - return appId; + return appModel; } } diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsShareGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsShareGoal.java index 7eaf805..bb069e2 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsShareGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsShareGoal.java @@ -30,6 +30,7 @@ import com.inteligr8.activiti.model.Datum; import com.inteligr8.activiti.model.ResultList; import com.inteligr8.alfresco.activiti.api.ModelsApi; import com.inteligr8.alfresco.activiti.model.GroupLight; +import com.inteligr8.alfresco.activiti.model.ModelRepresentation; import com.inteligr8.alfresco.activiti.model.PermissionLevel; import com.inteligr8.alfresco.activiti.model.PermissionLight; import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation; @@ -108,14 +109,12 @@ public class ApsShareGoal extends ApsAddressibleGoal { } private void shareModels(ModelsApi.ModelType modelType, Set readers, Set editors) { - ResultListDataRepresentation models = this.getApsApi().getModelsApi().get(null, null, modelType.getId(), null); + ResultList 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)) + for (ModelRepresentation model : models.getData()) { + if (this.modelName != null && !this.modelName.equals(model.getName())) continue; Set groupsAddressed = new HashSet<>(); @@ -123,7 +122,7 @@ public class ApsShareGoal extends ApsAddressibleGoal { Set editorsUnaddressed = new HashSet<>(editors); ShareInfoRequest changeRequest = new ShareInfoRequest(); - ResultList shares = this.getApsApi().getShareApi().getShareInfo(modelId.toString()); + ResultList shares = this.getApsApi().getShareApi().getShareInfo(model.getId().toString()); if (shares.getData() != null) { for (SharePermission share : shares.getData()) { if (share.getGroup() != null) { @@ -145,7 +144,7 @@ public class ApsShareGoal extends ApsAddressibleGoal { if (!changeRequest.getAdded().isEmpty() || !changeRequest.getUpdated().isEmpty() || !changeRequest.getRemoved().isEmpty()) { this.getLog().info("Sharing model: " + modelType + " => '" + modelName + "'"); - this.getApsApi().getShareApi().setShareInfo(modelId.toString(), changeRequest); + this.getApsApi().getShareApi().setShareInfo(model.getId().toString(), changeRequest); } } } diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java index 3d1b174..5c01b1a 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java @@ -46,7 +46,7 @@ public class DownloadAppGoal extends ApsAppAddressibleGoal { public void executeEnabled() throws MojoExecutionException, MojoFailureException { this.validateTargetDirectory(); - Long appId = this.findAppId(true); + Long appId = this.findAppModel(true).getId(); File appZip = this.downloadApp(appId); File toAppZip = new File(this.zipDirectory, this.apsAppName + ".zip"); diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/PublishAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/PublishAppGoal.java index de038d3..d5c4ac3 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/PublishAppGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/PublishAppGoal.java @@ -45,7 +45,7 @@ public class PublishAppGoal extends ApsAppAddressibleGoal { @Override public void executeEnabled() throws MojoExecutionException, MojoFailureException { - Long appId = this.findAppId(false); + Long appId = this.findAppModel(false).getId(); try { this.publishApp(appId); diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadAppGoal.java index 3e9b96f..8bc0990 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadAppGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadAppGoal.java @@ -29,6 +29,7 @@ import org.codehaus.plexus.component.annotations.Component; import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl; import com.inteligr8.alfresco.activiti.model.AppDefinitionUpdateResultRepresentation; import com.inteligr8.alfresco.activiti.model.FileMultipartJersey; +import com.inteligr8.alfresco.activiti.model.ModelRepresentation; /** * A class that implements an APS service upload goal. @@ -59,10 +60,10 @@ public class UploadAppGoal extends ApsAppAddressibleGoal { public void executeEnabled() throws MojoExecutionException, MojoFailureException { File sourceFile = this.validateSourceDirectory(); - Long appId = this.findAppId(false); + ModelRepresentation appModel = this.findAppModel(false); try { - this.uploadApp(appId, sourceFile); + this.uploadApp(appModel, sourceFile); } catch (IOException ie) { throw new MojoExecutionException("The APS App could not be uploaded", ie); } @@ -86,7 +87,7 @@ public class UploadAppGoal extends ApsAppAddressibleGoal { return sourceFile; } - private void uploadApp(Long appId, File appZip) throws IOException, MojoExecutionException { + private void uploadApp(ModelRepresentation appModel, File appZip) throws IOException, MojoExecutionException { ApsPublicRestApiJerseyImpl api = this.getApsApi(); FileInputStream fistream = new FileInputStream(appZip); @@ -94,7 +95,7 @@ public class UploadAppGoal extends ApsAppAddressibleGoal { try { FileMultipartJersey multipart = FileMultipartJersey.from(appZip.getName(), bistream); - if (appId == null) { + if (appModel == null) { if (this.publish) { if (this.dryRun) { this.getLog().info("[DRYRUN]: Uploading & publishing new APS App: " + this.apsAppName); @@ -115,19 +116,19 @@ public class UploadAppGoal extends ApsAppAddressibleGoal { } else { if (this.publish) { if (this.dryRun) { - this.getLog().info("[DRYRUN]: Uploading, versioning, & publishing APS App: " + this.apsAppName + " (" + appId + ")"); + this.getLog().info("[DRYRUN]: Uploading, versioning, & publishing APS App: " + this.apsAppName + " (" + appModel.getId() + ")"); } else { - this.getLog().info("Uploading, versioning, & publishing APS App: " + this.apsAppName + " (" + appId + ")"); - AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(appId, multipart); + this.getLog().info("Uploading, versioning, & publishing APS App: " + this.apsAppName + " (" + appModel.getId() + ")"); + AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(appModel.getId(), multipart); if (Boolean.TRUE.equals(appDefUpdate.getError())) throw new MojoExecutionException(appDefUpdate.getErrorDescription()); } } else { if (this.dryRun) { - this.getLog().info("[DRYRUN]: Uploading & versioning APS App: " + this.apsAppName + " (" + appId + ")"); + this.getLog().info("[DRYRUN]: Uploading & versioning APS App: " + this.apsAppName + " (" + appModel.getId() + ")"); } else { - this.getLog().info("Uploading & versioning APS App: " + this.apsAppName + " (" + appId + ")"); - api.getAppDefinitionsJerseyApi().importApp(appId, multipart, true); + this.getLog().info("Uploading & versioning APS App: " + this.apsAppName + " (" + appModel.getId() + ")"); + api.getAppDefinitionsJerseyApi().importApp(appModel.getId(), multipart, true); } } } diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/translator/ApsAppTranslator.java b/src/main/java/com/inteligr8/maven/aps/modeling/translator/ApsAppTranslator.java index 2e69b92..4e4a75d 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/translator/ApsAppTranslator.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/translator/ApsAppTranslator.java @@ -27,9 +27,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.inteligr8.activiti.model.Datum; +import com.inteligr8.activiti.model.ResultList; import com.inteligr8.alfresco.activiti.ApsPublicRestApi; import com.inteligr8.alfresco.activiti.api.ModelsApi.ModelType; import com.inteligr8.alfresco.activiti.model.GroupLight; +import com.inteligr8.alfresco.activiti.model.ModelRepresentation; import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation; import com.inteligr8.alfresco.activiti.model.Tenant; import com.inteligr8.maven.aps.modeling.crawler.ApsAppCrawlable; @@ -196,18 +198,15 @@ public class ApsAppTranslator implements ApsAppCrawlable { return map; } - @SuppressWarnings("unchecked") protected Index buildApsModelIndex(ModelType modelType) { - ResultListDataRepresentation results = this.api.getModelsApi().get("everyone", null, modelType.getId(), null); + ResultList results = this.api.getModelsApi().get("everyone", null, modelType.getId(), null); this.logger.debug("APS {} models found: {} out of {}", modelType, results.getSize(), results.getTotal()); Index map = new Index<>(results.getSize().intValue(), false); try { - for (Datum datum : results.getData()) { - Number defId = (Number)datum.getAdditionalProperties().get("id"); - String defName = (String)datum.getAdditionalProperties().get("name"); - map.put(defId.longValue(), defName); + for (ModelRepresentation model : results.getData()) { + map.put(model.getId(), model.getName()); // FIXME add paging support }