use of org.alfresco.service.cmr.replication.ReplicationDefinition in project alfresco-remote-api by Alfresco.
the class ReplicationDefinitionPut method buildModel.
@Override
protected Map<String, Object> buildModel(ReplicationModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {
// Which definition did they ask for?
String replicationDefinitionName = req.getServiceMatch().getTemplateVars().get("replication_definition_name");
ReplicationDefinition replicationDefinition = replicationService.loadReplicationDefinition(replicationDefinitionName);
// Does it exist?
if (replicationDefinition == null) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No Replication Definition found with that name");
}
// Grab the JSON, and prepare to update
try {
JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent()));
// Are they trying to rename?
if (json.has("name")) {
String jsonName = json.getString("name");
if (!jsonName.equals(replicationDefinitionName)) {
// Name has changed, ensure the new name is spare
if (replicationService.loadReplicationDefinition(jsonName) != null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "The specified new name is already in use");
}
// Rename it
replicationService.renameReplicationDefinition(replicationDefinitionName, jsonName);
// And grab the updated version post-rename
replicationDefinition = replicationService.loadReplicationDefinition(jsonName);
}
}
// Update everything else
updateDefinitionProperties(replicationDefinition, json);
// Save the changes
replicationService.saveReplicationDefinition(replicationDefinition);
} catch (IOException iox) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from request.", iox);
} catch (JSONException je) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from request.", je);
}
// Return the new details on it
return modelBuilder.buildDetails(replicationDefinition);
}
use of org.alfresco.service.cmr.replication.ReplicationDefinition in project alfresco-remote-api by Alfresco.
the class ReplicationDefinitionsPost method buildModel.
@Override
protected Map<String, Object> buildModel(ReplicationModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {
// Create our definition
ReplicationDefinition replicationDefinition = null;
JSONObject json;
try {
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
// Check for the required parameters
if (!json.has("name"))
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "name is required but wasn't supplied");
if (!json.has("description"))
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "description is required but wasn't supplied");
// Ensure one doesn't already exist with that name
String name = json.getString("name");
if (replicationService.loadReplicationDefinition(name) != null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "A replication definition already exists with that name");
}
// Create the definition
replicationDefinition = replicationService.createReplicationDefinition(name, json.getString("description"));
// Set the extra parts
updateDefinitionProperties(replicationDefinition, json);
// Save the changes
replicationService.saveReplicationDefinition(replicationDefinition);
} catch (IOException iox) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from request.", iox);
} catch (JSONException je) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from request.", je);
}
// Return the details on it
return modelBuilder.buildDetails(replicationDefinition);
}
use of org.alfresco.service.cmr.replication.ReplicationDefinition in project alfresco-remote-api by Alfresco.
the class ReplicationModelBuilder method buildSimpleList.
/**
* Build a model containing a list of simple definitions for the given
* list of Replication Definitions.
*/
protected Map<String, Object> buildSimpleList(List<ReplicationDefinition> replicationDefinitions, Comparator<Map<String, Object>> sorter) {
List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
// have some Replication Definitions to render
if (replicationDefinitions.size() > 0) {
List<ExecutionSummary> executing = actionTrackingService.getExecutingActions(replicationDefinitions.get(0).getActionDefinitionName());
for (ReplicationDefinition rd : replicationDefinitions) {
// Get the executing detail(s) for this definition
ExecutionDetails details = getExecutionDetails(rd, executing);
// Set the core details
Map<String, Object> rdm = new HashMap<String, Object>();
rdm.put(DEFINITION_NAME, rd.getReplicationName());
rdm.put(DEFINITION_ENABLED, rd.isEnabled());
// Do the status
setStatus(rd, details, rdm);
// In the summary form, we don't need end time or details
rdm.remove(DEFINITION_ENDED_AT);
rdm.remove(DEFINITION_RUNNING_ACTION_ID);
// Add to the list of finished models
models.add(rdm);
}
}
// Sort the entries
if (sorter != null) {
Collections.sort(models, sorter);
}
// Finish up
Map<String, Object> model = new HashMap<String, Object>();
model.put(MODEL_DATA_LIST, models);
return model;
}
use of org.alfresco.service.cmr.replication.ReplicationDefinition in project alfresco-remote-api by Alfresco.
the class RunningReplicationActionsGet method buildModel.
@Override
protected Map<String, Object> buildModel(RunningActionModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {
List<ExecutionSummary> actions = null;
// Do they want all replication actions, or only certain ones?
String name = req.getParameter("name");
if (name != null) {
// Try to find a replication definition with this name
ReplicationDefinition rd = replicationService.loadReplicationDefinition(name);
// Look up what's running
if (rd != null) {
actions = actionTrackingService.getExecutingActions(rd);
}
} else {
// All replication actions
actions = actionTrackingService.getExecutingActions(ReplicationDefinitionImpl.EXECUTOR_NAME);
}
// Build the model list
return modelBuilder.buildSimpleList(actions);
}
use of org.alfresco.service.cmr.replication.ReplicationDefinition in project alfresco-remote-api by Alfresco.
the class RunningReplicationActionsPost method identifyAction.
@Override
protected Action identifyAction(WebScriptRequest req, Status status, Cache cache) {
// Which action did they ask for?
String name = req.getParameter("name");
if (name == null) {
try {
JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent()));
if (!json.has("name")) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not find required 'name' parameter");
}
name = json.getString("name");
} catch (IOException iox) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from request.", iox);
} catch (JSONException je) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from request.", je);
}
}
// Load the specified replication definition
ReplicationDefinition replicationDefinition = replicationService.loadReplicationDefinition(name);
return replicationDefinition;
}
Aggregations