mapping model not just ID
This commit is contained in:
parent
a65a6df1f8
commit
0b9473465e
2
pom.xml
2
pom.xml
@ -51,7 +51,7 @@
|
||||
<dependency>
|
||||
<groupId>com.inteligr8.alfresco</groupId>
|
||||
<artifactId>aps-public-rest-api</artifactId>
|
||||
<version>2.0.15</version>
|
||||
<version>2.0.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.inteligr8.alfresco</groupId>
|
||||
|
@ -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<String, Long> findAppNameIds() {
|
||||
protected Map<String, ModelRepresentation> buildAppNameMap() {
|
||||
ApsPublicRestApiJerseyImpl api = this.getApsApi();
|
||||
|
||||
Map<String, Long> apps = new HashMap<>(16);
|
||||
Map<String, ModelRepresentation> apps = new HashMap<>(16);
|
||||
|
||||
this.getLog().debug("Searching for all APS Apps");
|
||||
ResultListDataRepresentation<Datum> results = api.getModelsApi().get("everyone", null, ModelType.App.getId(), null);
|
||||
ResultList<ModelRepresentation> 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<String, Long> apps = this.findAppNameIds();
|
||||
Long appId = apps.get(this.apsAppName);
|
||||
if (failOnNotFound && appId == null)
|
||||
protected ModelRepresentation findAppModelByName(String appName, boolean failOnNotFound) throws MojoExecutionException {
|
||||
Map<String, ModelRepresentation> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<String> readers, Set<String> editors) {
|
||||
ResultListDataRepresentation<Datum> models = this.getApsApi().getModelsApi().get(null, null, modelType.getId(), null);
|
||||
ResultList<ModelRepresentation> 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<String> groupsAddressed = new HashSet<>();
|
||||
@ -123,7 +122,7 @@ public class ApsShareGoal extends ApsAddressibleGoal {
|
||||
Set<String> editorsUnaddressed = new HashSet<>(editors);
|
||||
ShareInfoRequest changeRequest = new ShareInfoRequest();
|
||||
|
||||
ResultList<SharePermission> shares = this.getApsApi().getShareApi().getShareInfo(modelId.toString());
|
||||
ResultList<SharePermission> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Long, String> buildApsModelIndex(ModelType modelType) {
|
||||
ResultListDataRepresentation<Datum> results = this.api.getModelsApi().get("everyone", null, modelType.getId(), null);
|
||||
ResultList<ModelRepresentation> results = this.api.getModelsApi().get("everyone", null, modelType.getId(), null);
|
||||
this.logger.debug("APS {} models found: {} out of {}", modelType, results.getSize(), results.getTotal());
|
||||
|
||||
Index<Long, String> 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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user