mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Start on ALF-4130 (F105) - replication details fetch webscript.
Basics are returned, and unit tested, but the remainder of the details need to be retrieved, computed, output and tested git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21546 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<webscript>
|
||||
<shortname>Get Replication Definition</shortname>
|
||||
<description>Gets the details of a persisted replication definition.</description>
|
||||
<url>/api/replication-definition/{replication_definition_name}</url>
|
||||
<format default="json"/>
|
||||
<authentication>admin</authentication>
|
||||
<transaction allow="readonly">required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,2 @@
|
||||
<#import "replication-definition.lib.ftl" as replicationDefLib />
|
||||
<@replicationDefLib.replicationDefinitionJSON replicationDefinition=replicationDefinition />
|
@@ -17,6 +17,8 @@
|
||||
{
|
||||
"name": "${replicationDefinition.name}",
|
||||
"status" : "${replicationDefinition.status}",
|
||||
"startedAt" : <#if replicationDefinition.startedAt??>"${replicationDefinition.startedAt}"<#else>null</#if>,
|
||||
"endedAt" : <#if replicationDefinition.endedAt??>"${replicationDefinition.endedAt}"<#else>null</#if>,
|
||||
"enabled" : ${replicationDefinition.enabled?string},
|
||||
<#-- TODO The rest of the fields -->
|
||||
}
|
||||
|
@@ -853,4 +853,10 @@
|
||||
parent="abstractReplicationWebScript">
|
||||
</bean>
|
||||
|
||||
<!-- Get the details of a replication definition -->
|
||||
<bean id="webscript.org.alfresco.repository.replication.replication-definition.get"
|
||||
class="org.alfresco.repo.web.scripts.replication.ReplicationDefinitionGet"
|
||||
parent="abstractReplicationWebScript">
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.replication;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.replication.ReplicationDefinition;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
|
||||
/**
|
||||
* @author Nick Burch
|
||||
* @since 3.4
|
||||
*/
|
||||
public class ReplicationDefinitionGet extends AbstractReplicationWebscript
|
||||
{
|
||||
@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"
|
||||
);
|
||||
}
|
||||
|
||||
// Have it turned into simple models
|
||||
return modelBuilder.buildDetails(replicationDefinition);
|
||||
}
|
||||
}
|
@@ -43,6 +43,7 @@ import org.alfresco.util.ISO8601DateFormat;
|
||||
*/
|
||||
public class ReplicationModelBuilder
|
||||
{
|
||||
protected static final String MODEL_DATA_ITEM = "replicationDefinition";
|
||||
protected static final String MODEL_DATA_LIST = "replicationDefinitions";
|
||||
|
||||
protected static final String DEFINITION_NAME = "name";
|
||||
@@ -164,6 +165,30 @@ public class ReplicationModelBuilder
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build a model containing the full, detailed definition for the given
|
||||
* Replication Definition.
|
||||
*/
|
||||
protected Map<String, Object> buildDetails(ReplicationDefinition rd) {
|
||||
Map<String, Object> rdm = new HashMap<String,Object>();
|
||||
|
||||
// Set the core details
|
||||
rdm.put(DEFINITION_NAME, rd.getReplicationName());
|
||||
rdm.put(DEFINITION_ENABLED, rd.isEnabled());
|
||||
// TODO
|
||||
|
||||
// Do the status
|
||||
setStatus(rd, rdm);
|
||||
|
||||
// Expand out the payload details
|
||||
// TODO
|
||||
|
||||
Map<String, Object> model = new HashMap<String,Object>();
|
||||
model.put(MODEL_DATA_ITEM, rdm);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Figures out the status that's one of:
|
||||
* New|Running|CancelRequested|Completed|Failed|Cancelled
|
||||
|
@@ -326,6 +326,72 @@ public class ReplicationRestApiTest extends BaseWebScriptTest
|
||||
assertEquals("/api/replication-definition/Test2", jsonRD.get("details"));
|
||||
}
|
||||
|
||||
public void testReplicationDefinitionGet() throws Exception
|
||||
{
|
||||
Response response;
|
||||
|
||||
|
||||
// Not allowed if you're not an admin
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
|
||||
response = sendRequest(new GetRequest(URL_DEFINITION + "madeup"), Status.STATUS_UNAUTHORIZED);
|
||||
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
|
||||
response = sendRequest(new GetRequest(URL_DEFINITION + "madeup"), Status.STATUS_UNAUTHORIZED);
|
||||
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
|
||||
|
||||
|
||||
// If an invalid name is given, you get a 404
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
response = sendRequest(new GetRequest(URL_DEFINITION + "madeup"), 404);
|
||||
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
|
||||
|
||||
|
||||
// Add a definition, it should show up
|
||||
ReplicationDefinition rd = replicationService.createReplicationDefinition("Test1", "Testing");
|
||||
replicationService.saveReplicationDefinition(rd);
|
||||
response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
|
||||
assertEquals(Status.STATUS_OK, response.getStatus());
|
||||
|
||||
String jsonStr = response.getContentAsString();
|
||||
System.err.println(jsonStr);
|
||||
JSONObject json = new JSONObject(jsonStr);
|
||||
assertNotNull(json);
|
||||
|
||||
// Check
|
||||
// TODO
|
||||
assertEquals("Test1", json.get("name"));
|
||||
assertEquals("New", json.get("status"));
|
||||
assertEquals(true, json.get("enabled"));
|
||||
assertEquals(JSONObject.NULL, json.get("startedAt"));
|
||||
|
||||
|
||||
// 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);
|
||||
|
||||
|
||||
// Add some payload details, ensure that they get expanded
|
||||
// as they should be
|
||||
|
||||
|
||||
// Add a 2nd and 3rd
|
||||
rd = replicationService.createReplicationDefinition("Test2", "2nd Testing");
|
||||
replicationService.saveReplicationDefinition(rd);
|
||||
|
||||
// Original one comes back unchanged
|
||||
// TODO
|
||||
|
||||
// They show up things as expected
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
|
Reference in New Issue
Block a user