Search in sources :

Example 11 with ReplicationDefinition

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);
}
Also used : JSONTokener(org.json.JSONTokener) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONObject(org.json.JSONObject) ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 12 with 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);
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 13 with 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;
}
Also used : ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExecutionSummary(org.alfresco.service.cmr.action.ExecutionSummary) ExecutionDetails(org.alfresco.service.cmr.action.ExecutionDetails) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with ReplicationDefinition

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);
}
Also used : ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition) ExecutionSummary(org.alfresco.service.cmr.action.ExecutionSummary)

Example 15 with ReplicationDefinition

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;
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition) JSONException(org.json.JSONException) IOException(java.io.IOException)

Aggregations

ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)22 JSONObject (org.json.JSONObject)12 UserTransaction (javax.transaction.UserTransaction)11 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)11 JSONArray (org.json.JSONArray)7 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)6 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)5 ActionImpl (org.alfresco.repo.action.ActionImpl)4 IOException (java.io.IOException)3 ExecutionSummary (org.alfresco.service.cmr.action.ExecutionSummary)3 JSONException (org.json.JSONException)3 JSONTokener (org.json.JSONTokener)3 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)3 TestPersonManager (org.alfresco.repo.security.person.TestPersonManager)2 ExecutionDetails (org.alfresco.service.cmr.action.ExecutionDetails)2 MutableAuthenticationService (org.alfresco.service.cmr.security.MutableAuthenticationService)2 PersonService (org.alfresco.service.cmr.security.PersonService)2 ApplicationContext (org.springframework.context.ApplicationContext)2 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)2 ArrayList (java.util.ArrayList)1