use of org.alfresco.service.cmr.replication.ReplicationDefinition in project alfresco-remote-api by Alfresco.
the class ReplicationDefinitionDelete 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");
}
// Delete it
replicationService.deleteReplicationDefinition(replicationDefinition);
// Report that we have deleted it
status.setCode(Status.STATUS_NO_CONTENT);
status.setMessage("Replication Definition deleted");
status.setRedirect(true);
return null;
}
use of org.alfresco.service.cmr.replication.ReplicationDefinition in project alfresco-remote-api by Alfresco.
the class RunningActionRestApiTest method testRunningActionGet.
public void testRunningActionGet() throws Exception {
Response response;
// Not allowed if you're not an admin
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + "MadeUp"), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + "MadeUp"), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
// If not found, you get a 404
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + "MadeUp"), Status.STATUS_NOT_FOUND);
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
// Create one
ReplicationDefinition rd = replicationService.createReplicationDefinition("Test1", "Testing");
replicationService.saveReplicationDefinition(rd);
actionTrackingService.recordActionExecuting(rd);
String id = rd.getId();
String instance = Integer.toString(((ActionImpl) rd).getExecutionInstance());
String startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
String key1 = "replicationActionExecutor=" + id + "=" + instance;
// Fetch the details of it
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + key1), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
String jsonStr = response.getContentAsString();
JSONObject jsonRD = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(jsonRD);
assertEquals(id, jsonRD.get("actionId"));
assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(instance, jsonRD.get("actionInstance"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(startedAt, jsonRD.get("startedAt"));
assertEquals(false, jsonRD.getBoolean("cancelRequested"));
assertEquals("/" + URL_RUNNING_ACTION + key1, jsonRD.get("details"));
// Ensure we didn't get any unexpected data back,
// only the keys we should have done
JSONArray keys = jsonRD.names();
for (int i = 0; i < keys.length(); i++) {
String key = keys.getString(0);
if (key.equals("actionId") || key.equals("actionType") || key.equals("actionInstance") || key.equals("actionNodeRef") || key.equals("startedAt") || key.equals("cancelRequested") || key.equals("details")) {
// All good
} else {
fail("Unexpected key '" + key + "' found in json, raw json is\n" + jsonStr);
}
}
// Add another which is cancelled, check that
// we get the correct, different details for it
rd = replicationService.createReplicationDefinition("Test2", "Testing");
replicationService.saveReplicationDefinition(rd);
actionTrackingService.recordActionExecuting(rd);
actionTrackingService.requestActionCancellation(rd);
String id2 = rd.getId();
String instance2 = Integer.toString(((ActionImpl) rd).getExecutionInstance());
String startedAt2 = ISO8601DateFormat.format(rd.getExecutionStartDate());
String key2 = "replicationActionExecutor=" + id2 + "=" + instance2;
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + key2), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
jsonRD = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(jsonRD);
assertEquals(id2, jsonRD.get("actionId"));
assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(instance2, jsonRD.get("actionInstance"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(startedAt2, jsonRD.get("startedAt"));
assertEquals(true, jsonRD.getBoolean("cancelRequested"));
assertEquals("/" + URL_RUNNING_ACTION + key2, jsonRD.get("details"));
// Check that the original is unchanged
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + key1), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
rd = replicationService.loadReplicationDefinition("Test1");
jsonStr = response.getContentAsString();
jsonRD = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(jsonRD);
assertEquals(id, jsonRD.get("actionId"));
assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(instance, jsonRD.get("actionInstance"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(startedAt, jsonRD.get("startedAt"));
assertEquals(false, jsonRD.getBoolean("cancelRequested"));
assertEquals("/" + URL_RUNNING_ACTION + key1, jsonRD.get("details"));
// Add one that is pending - has everything except start date
rd = replicationService.createReplicationDefinition("Test3", "Testing");
replicationService.saveReplicationDefinition(rd);
actionTrackingService.recordActionPending(rd);
String id3 = rd.getId();
String instance3 = Integer.toString(((ActionImpl) rd).getExecutionInstance());
String key3 = "replicationActionExecutor=" + id3 + "=" + instance3;
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + key3), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
jsonRD = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(jsonRD);
assertEquals(id3, jsonRD.get("actionId"));
assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(instance3, jsonRD.get("actionInstance"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(JSONObject.NULL, jsonRD.get("startedAt"));
assertEquals(false, jsonRD.getBoolean("cancelRequested"));
assertEquals("/" + URL_RUNNING_ACTION + key3, jsonRD.get("details"));
}
use of org.alfresco.service.cmr.replication.ReplicationDefinition in project alfresco-remote-api by Alfresco.
the class RunningActionRestApiTest method setUp.
@SuppressWarnings("unchecked")
@Override
protected void setUp() throws Exception {
super.setUp();
ApplicationContext appContext = getServer().getApplicationContext();
nodeService = (NodeService) appContext.getBean("NodeService");
replicationService = (ReplicationService) appContext.getBean("ReplicationService");
actionTrackingService = (ActionTrackingService) appContext.getBean("actionTrackingService");
repositoryHelper = (Repository) appContext.getBean("repositoryHelper");
transactionService = (TransactionService) appContext.getBean("transactionService");
executingActionsCache = (SimpleCache<String, ExecutionDetails>) appContext.getBean("executingActionsCache");
MutableAuthenticationService authenticationService = (MutableAuthenticationService) appContext.getBean("AuthenticationService");
PersonService personService = (PersonService) appContext.getBean("PersonService");
personManager = new TestPersonManager(authenticationService, personService, nodeService);
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
personManager.createPerson(USER_NORMAL);
// Ensure we start with no replication definitions
// (eg another test left them behind)
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
for (ReplicationDefinition rd : replicationService.loadReplicationDefinitions()) {
replicationService.deleteReplicationDefinition(rd);
}
txn.commit();
// Grab a reference to the data dictionary
dataDictionary = nodeService.getChildByName(repositoryHelper.getCompanyHome(), ContentModel.ASSOC_CONTAINS, "Data Dictionary");
AuthenticationUtil.clearCurrentSecurityContext();
}
use of org.alfresco.service.cmr.replication.ReplicationDefinition in project alfresco-remote-api by Alfresco.
the class RunningActionRestApiTest method tearDown.
@Override
protected void tearDown() throws Exception {
super.tearDown();
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
personManager.clearPeople();
// Zap any replication definitions we created
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
for (ReplicationDefinition rd : replicationService.loadReplicationDefinitions()) {
replicationService.deleteReplicationDefinition(rd);
}
AuthenticationUtil.clearCurrentSecurityContext();
// Clear out the running actions
for (ExecutionSummary es : actionTrackingService.getAllExecutingActions()) {
executingActionsCache.remove(AbstractActionWebscript.getRunningId(es));
}
txn.commit();
}
use of org.alfresco.service.cmr.replication.ReplicationDefinition in project alfresco-remote-api by Alfresco.
the class ReplicationRestApiTest method testReplicationDefinitionsGet.
public void testReplicationDefinitionsGet() throws Exception {
Response response;
// Not allowed if you're not an admin
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
response = sendRequest(new GetRequest(URL_DEFINITIONS), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
response = sendRequest(new GetRequest(URL_DEFINITIONS), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
// If no definitions exist, you don't get anything back
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
response = sendRequest(new GetRequest(URL_DEFINITIONS), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
String jsonStr = response.getContentAsString();
JSONObject json = new JSONObject(jsonStr);
JSONArray results = json.getJSONArray("data");
assertNotNull(results);
assertEquals(0, results.length());
// Add a definition, it should show up
ReplicationDefinition rd = replicationService.createReplicationDefinition("Test1", "Testing");
replicationService.saveReplicationDefinition(rd);
response = sendRequest(new GetRequest(URL_DEFINITIONS), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
results = json.getJSONArray("data");
assertNotNull(results);
assertEquals(1, results.length());
JSONObject jsonRD = (JSONObject) results.get(0);
assertNotNull(jsonRD);
assertEquals("Test1", jsonRD.get("name"));
assertEquals("New", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(JSONObject.NULL, jsonRD.get("startedAt"));
assertEquals("/api/replication-definition/Test1", jsonRD.get("details"));
// Ensure we didn't get any unexpected data back,
// only the keys we should have done
JSONArray keys = jsonRD.names();
for (int i = 0; i < keys.length(); i++) {
String key = keys.getString(0);
if (key.equals("name") || key.equals("status") || key.equals("startedAt") || key.equals("enabled") || key.equals("details")) {
// All good
} else {
fail("Unexpected key '" + key + "' found in json, raw json is\n" + jsonStr);
}
}
// Mark it as pending execution, and re-check
actionTrackingService.recordActionPending(rd);
response = sendRequest(new GetRequest(URL_DEFINITIONS), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
results = json.getJSONArray("data");
assertNotNull(results);
assertEquals(1, results.length());
jsonRD = (JSONObject) results.get(0);
assertNotNull(jsonRD);
assertEquals("Test1", jsonRD.get("name"));
assertEquals("Pending", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(JSONObject.NULL, jsonRD.get("startedAt"));
assertEquals("/api/replication-definition/Test1", jsonRD.get("details"));
// Change the status to running, and re-check
actionTrackingService.recordActionExecuting(rd);
String startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
response = sendRequest(new GetRequest(URL_DEFINITIONS), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
results = json.getJSONArray("data");
assertNotNull(results);
assertEquals(1, results.length());
jsonRD = (JSONObject) results.get(0);
assertNotNull(jsonRD);
assertEquals("Test1", jsonRD.get("name"));
assertEquals("Running", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(startedAt, jsonRD.getJSONObject("startedAt").get("iso8601"));
assertEquals("/api/replication-definition/Test1", jsonRD.get("details"));
// Add a 2nd and 3rd
rd = replicationService.createReplicationDefinition("Test2", "2nd Testing");
replicationService.saveReplicationDefinition(rd);
rd = replicationService.createReplicationDefinition("AnotherTest", "3rd Testing");
replicationService.saveReplicationDefinition(rd);
// They should come back sorted by name
response = sendRequest(new GetRequest(URL_DEFINITIONS), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
results = json.getJSONArray("data");
assertNotNull(results);
assertEquals(3, results.length());
jsonRD = (JSONObject) results.get(0);
assertNotNull(jsonRD);
assertEquals("AnotherTest", jsonRD.get("name"));
assertEquals("New", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(JSONObject.NULL, jsonRD.get("startedAt"));
assertEquals("/api/replication-definition/AnotherTest", jsonRD.get("details"));
jsonRD = (JSONObject) results.get(1);
assertNotNull(jsonRD);
assertEquals("Test1", jsonRD.get("name"));
assertEquals("Running", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(startedAt, jsonRD.getJSONObject("startedAt").get("iso8601"));
assertEquals("/api/replication-definition/Test1", jsonRD.get("details"));
jsonRD = (JSONObject) results.get(2);
assertNotNull(jsonRD);
assertEquals("Test2", jsonRD.get("name"));
assertEquals("New", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(JSONObject.NULL, jsonRD.get("startedAt"));
assertEquals("/api/replication-definition/Test2", jsonRD.get("details"));
// Sort by status
response = sendRequest(new GetRequest(URL_DEFINITIONS + "?sort=status"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
results = json.getJSONArray("data");
assertNotNull(results);
assertEquals(3, results.length());
// New, name sorts higher
jsonRD = (JSONObject) results.get(0);
assertNotNull(jsonRD);
assertEquals("AnotherTest", jsonRD.get("name"));
assertEquals("New", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(JSONObject.NULL, jsonRD.get("startedAt"));
assertEquals("/api/replication-definition/AnotherTest", jsonRD.get("details"));
// New, name sorts lower
jsonRD = (JSONObject) results.get(1);
assertNotNull(jsonRD);
assertEquals("Test2", jsonRD.get("name"));
assertEquals("New", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(JSONObject.NULL, jsonRD.get("startedAt"));
assertEquals("/api/replication-definition/Test2", jsonRD.get("details"));
// Running
jsonRD = (JSONObject) results.get(2);
assertNotNull(jsonRD);
assertEquals("Test1", jsonRD.get("name"));
assertEquals("Running", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(startedAt, jsonRD.getJSONObject("startedAt").get("iso8601"));
assertEquals("/api/replication-definition/Test1", jsonRD.get("details"));
// Set start times and statuses on these other two
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
rd = replicationService.loadReplicationDefinition("Test2");
actionTrackingService.recordActionExecuting(rd);
actionTrackingService.recordActionComplete(rd);
String startedAt2 = ISO8601DateFormat.format(rd.getExecutionStartDate());
txn.commit();
// Try the different sorts
response = sendRequest(new GetRequest(URL_DEFINITIONS + "?sort=status"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
results = json.getJSONArray("data");
assertNotNull(results);
assertEquals(3, results.length());
// Complete
jsonRD = (JSONObject) results.get(0);
assertNotNull(jsonRD);
assertEquals("Test2", jsonRD.get("name"));
assertEquals("Completed", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(startedAt2, jsonRD.getJSONObject("startedAt").get("iso8601"));
assertEquals("/api/replication-definition/Test2", jsonRD.get("details"));
// New
jsonRD = (JSONObject) results.get(1);
assertNotNull(jsonRD);
assertEquals("AnotherTest", jsonRD.get("name"));
assertEquals("New", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(JSONObject.NULL, jsonRD.get("startedAt"));
assertEquals("/api/replication-definition/AnotherTest", jsonRD.get("details"));
// Running
jsonRD = (JSONObject) results.get(2);
assertNotNull(jsonRD);
assertEquals("Test1", jsonRD.get("name"));
assertEquals("Running", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(startedAt, jsonRD.getJSONObject("startedAt").get("iso8601"));
assertEquals("/api/replication-definition/Test1", jsonRD.get("details"));
// By last run
response = sendRequest(new GetRequest(URL_DEFINITIONS + "?sort=lastRun"), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
results = json.getJSONArray("data");
assertNotNull(results);
assertEquals(3, results.length());
// Ran most recently
jsonRD = (JSONObject) results.get(0);
assertNotNull(jsonRD);
assertEquals("Test2", jsonRD.get("name"));
assertEquals("Completed", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(startedAt2, jsonRD.getJSONObject("startedAt").get("iso8601"));
assertEquals("/api/replication-definition/Test2", jsonRD.get("details"));
// Ran least recently
jsonRD = (JSONObject) results.get(1);
assertNotNull(jsonRD);
assertEquals("Test1", jsonRD.get("name"));
assertEquals("Running", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(startedAt, jsonRD.getJSONObject("startedAt").get("iso8601"));
assertEquals("/api/replication-definition/Test1", jsonRD.get("details"));
// Never run last
jsonRD = (JSONObject) results.get(2);
assertNotNull(jsonRD);
assertEquals("AnotherTest", jsonRD.get("name"));
assertEquals("New", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(JSONObject.NULL, jsonRD.get("startedAt"));
assertEquals("/api/replication-definition/AnotherTest", jsonRD.get("details"));
// Cancel one of these
rd = replicationService.loadReplicationDefinition("AnotherTest");
rd.setEnabled(false);
replicationService.saveReplicationDefinition(rd);
actionTrackingService.recordActionExecuting(rd);
actionTrackingService.requestActionCancellation(rd);
String startedAt3 = ISO8601DateFormat.format(rd.getExecutionStartDate());
response = sendRequest(new GetRequest(URL_DEFINITIONS), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
results = json.getJSONArray("data");
assertNotNull(results);
assertEquals(3, results.length());
jsonRD = (JSONObject) results.get(0);
assertNotNull(jsonRD);
assertEquals("AnotherTest", jsonRD.get("name"));
assertEquals("CancelRequested", jsonRD.get("status"));
assertEquals(false, jsonRD.get("enabled"));
assertEquals(startedAt3, jsonRD.getJSONObject("startedAt").get("iso8601"));
assertEquals("/api/replication-definition/AnotherTest", jsonRD.get("details"));
jsonRD = (JSONObject) results.get(1);
assertNotNull(jsonRD);
assertEquals("Test1", jsonRD.get("name"));
assertEquals("Running", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(startedAt, jsonRD.getJSONObject("startedAt").get("iso8601"));
assertEquals("/api/replication-definition/Test1", jsonRD.get("details"));
jsonRD = (JSONObject) results.get(2);
assertNotNull(jsonRD);
assertEquals("Test2", jsonRD.get("name"));
assertEquals("Completed", jsonRD.get("status"));
assertEquals(true, jsonRD.get("enabled"));
assertEquals(startedAt2, jsonRD.getJSONObject("startedAt").get("iso8601"));
assertEquals("/api/replication-definition/Test2", jsonRD.get("details"));
}
Aggregations