diff --git a/src/main/java/org/alfresco/com/FilePlanComponentAlias.java b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentAlias.java
similarity index 96%
rename from src/main/java/org/alfresco/com/FilePlanComponentAlias.java
rename to src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentAlias.java
index 13dc3dbd68..45ada4d9ec 100644
--- a/src/main/java/org/alfresco/com/FilePlanComponentAlias.java
+++ b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentAlias.java
@@ -9,7 +9,7 @@
* agreement is prohibited.
* #L%
*/
-package org.alfresco.com;
+package org.alfresco.com.fileplancomponents;
/**
* File plan component alias enumeration
diff --git a/src/main/java/org/alfresco/com/FilePlanComponentFields.java b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java
similarity index 94%
rename from src/main/java/org/alfresco/com/FilePlanComponentFields.java
rename to src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java
index 76b91035c4..0f9b959462 100644
--- a/src/main/java/org/alfresco/com/FilePlanComponentFields.java
+++ b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java
@@ -9,7 +9,7 @@
* agreement is prohibited.
* #L%
*/
-package org.alfresco.com;
+package org.alfresco.com.fileplancomponents;
/**
* FIXME: Document me :)
diff --git a/src/main/java/org/alfresco/com/FilePlanComponentType.java b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentType.java
similarity index 97%
rename from src/main/java/org/alfresco/com/FilePlanComponentType.java
rename to src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentType.java
index 432178c75e..ebf8cc070d 100644
--- a/src/main/java/org/alfresco/com/FilePlanComponentType.java
+++ b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentType.java
@@ -9,7 +9,7 @@
* agreement is prohibited.
* #L%
*/
-package org.alfresco.com;
+package org.alfresco.com.fileplancomponents;
/**
* File plan component type enumeration
diff --git a/src/main/java/org/alfresco/com/site/RMSiteCompliance.java b/src/main/java/org/alfresco/com/site/RMSiteCompliance.java
new file mode 100644
index 0000000000..76f0bf4926
--- /dev/null
+++ b/src/main/java/org/alfresco/com/site/RMSiteCompliance.java
@@ -0,0 +1,24 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * License rights for this program may be obtained from Alfresco Software, Ltd.
+ * pursuant to a written agreement and any use of this program without such an
+ * agreement is prohibited.
+ * #L%
+ */
+package org.alfresco.com.site;
+
+/**
+ * RM Site compliance
+ *
+ * @author Tuna Aksoy
+ * @since 1.0
+ */
+public enum RMSiteCompliance
+{
+ STANDARD,
+ DOD5015
+}
diff --git a/src/main/java/org/alfresco/com/site/RMSiteFields.java b/src/main/java/org/alfresco/com/site/RMSiteFields.java
new file mode 100644
index 0000000000..c7c65f0d06
--- /dev/null
+++ b/src/main/java/org/alfresco/com/site/RMSiteFields.java
@@ -0,0 +1,37 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * License rights for this program may be obtained from Alfresco Software, Ltd.
+ * pursuant to a written agreement and any use of this program without such an
+ * agreement is prohibited.
+ * #L%
+ */
+package org.alfresco.com.site;
+
+/**
+ *RM Site properties from the RM Model Schema
+ *"entry": {
+ * "id": "string",
+ * "guid": "string",
+ * "title": "string",
+ * "description": "string",
+ * "visibility": "{@link org.springframework.social.alfresco.api.entities.Site.Visibility}",
+ * "compliance": "{@link RMSiteCompliance}",
+ * "role": "{@link org.alfresco.utility.constants.UserRole}"
+ *}
+ * @author Tuna Aksoy
+ * @author Rodica Sutu
+ * @since 1.0
+ */
+public class RMSiteFields
+{
+ public static final String ID = "id";
+ public static final String COMPLIANCE = "compliance";
+ public static final String TITLE = "title";
+ public static final String DESCRIPTION = "description";
+ public static final String VISIBILITY ="visibility";
+ public static final String ROLE = "role";
+}
diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponent.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java
similarity index 96%
rename from src/main/java/org/alfresco/rest/model/FilePlanComponent.java
rename to src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java
index efe28755fc..874e617065 100644
--- a/src/main/java/org/alfresco/rest/model/FilePlanComponent.java
+++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java
@@ -9,9 +9,9 @@
* agreement is prohibited.
* #L%
*/
-package org.alfresco.rest.model;
+package org.alfresco.rest.model.fileplancomponents;
-import static org.alfresco.com.FilePlanComponentFields.PROPERTIES;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java
similarity index 84%
rename from src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java
rename to src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java
index dbb1cbb82f..e3a25084ce 100644
--- a/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java
+++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java
@@ -9,11 +9,11 @@
* agreement is prohibited.
* #L%
*/
-package org.alfresco.rest.model;
+package org.alfresco.rest.model.fileplancomponents;
-import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_HOLD_REASON;
-import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_TITLE;
-import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_HOLD_REASON;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
diff --git a/src/main/java/org/alfresco/rest/model/site/RMSite.java b/src/main/java/org/alfresco/rest/model/site/RMSite.java
new file mode 100644
index 0000000000..960f518488
--- /dev/null
+++ b/src/main/java/org/alfresco/rest/model/site/RMSite.java
@@ -0,0 +1,47 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * License rights for this program may be obtained from Alfresco Software, Ltd.
+ * pursuant to a written agreement and any use of this program without such an
+ * agreement is prohibited.
+ * #L%
+ */
+package org.alfresco.rest.model.site;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import org.alfresco.com.site.RMSiteCompliance;
+import org.alfresco.rest.model.RestSiteModel;
+
+/**
+ * POJO for RM Site component
+ *
+ * @author Rodica Sutu
+ * @since 1.0
+ */
+public class RMSite extends RestSiteModel
+{
+ @JsonProperty (required = true)
+ private RMSiteCompliance compliance;
+
+ /**
+ * Helper method to set RM site compliance
+ * @param compliance {@link RMSiteCompliance} the compliance to set
+ */
+ public void setCompliance(RMSiteCompliance compliance)
+ {
+ this.compliance = compliance;
+ }
+
+ /**
+ * Helper method to get RM site compliance
+ * @return compliance the RM Site compliance to get
+ */
+ public RMSiteCompliance getCompliance()
+ {
+ return compliance;
+ }
+}
diff --git a/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java b/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java
new file mode 100644
index 0000000000..7cb99889cc
--- /dev/null
+++ b/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java
@@ -0,0 +1,123 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * License rights for this program may be obtained from Alfresco Software, Ltd.
+ * pursuant to a written agreement and any use of this program without such an
+ * agreement is prohibited.
+ * #L%
+ */
+package org.alfresco.rest.requests;
+
+import static org.alfresco.rest.core.RestRequest.requestWithBody;
+import static org.alfresco.rest.core.RestRequest.simpleRequest;
+import static org.springframework.http.HttpMethod.DELETE;
+import static org.springframework.http.HttpMethod.GET;
+import static org.springframework.http.HttpMethod.POST;
+import static org.springframework.http.HttpMethod.PUT;
+
+import com.google.gson.JsonObject;
+
+import org.alfresco.rest.core.RestAPI;
+import org.alfresco.rest.model.site.RMSite;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+/**
+ * File plan component REST API Wrapper
+ *
+ * @author Tuna Aksoy
+ * @author Rodica Sutu
+ * @since 1.0
+ */
+@Component
+@Scope (value = "prototype")
+public class RMSiteAPI extends RestAPI
+{
+ /**
+ * Get the RM site
+ *
+ * @return The {@link RMSite} for the given file plan component id
+ * @throws Exception for the following cases:
+ *
+ * - Api Response code 400 Invalid parameter: GET request is supported only for the RM site
+ * - Api Response code 401 If authentication failed
+ * - Api Response code 409 If RM Site does not exist
+ * - Api Response code default Unexpected error
+ *
+ */
+ public RMSite getSite() throws Exception
+ {
+ return usingRestWrapper().processModel(RMSite.class, simpleRequest(
+ GET,
+ "sites/rm"
+ ));
+ }
+
+ /**
+ * Create the RM site
+ *
+ * @param rmSiteProperties The properties of the rm site to be created
+ * @return The {@link RMSite} with the given properties
+ * @throws Exception for the following cases:
+ *
+ * - Api Response code 400 Invalid parameter: title, or description exceed the maximum length; or siteBodyCreate invalid
+ * - Api Response code 401 If authentication failed
+ *
- Api Response code 409 RM Site already exists
+ * - Api Response code default Unexpected error
+ *
+ */
+ public RMSite createRMSite(JsonObject rmSiteProperties) throws Exception
+ {
+ return usingRestWrapper().processModel(RMSite.class, requestWithBody(
+ POST,
+ rmSiteProperties.toString(),
+ "sites"
+ ));
+ }
+
+ /**
+ * Delete RM site
+ * @throws Exception for the following cases:
+ *
+ * - Api Response code 400 Invalid parameter: DELETE request is supported only for the RM site
+ * - Api Response code 401 If authentication failed
+ *
- Api Response code 403 Current user does not have permission to delete the site that is visible to them.
+ * - Api Response code 404 RM site does not exist
+ * - Api Response code default Unexpected error
+ *
+ */
+ public void deleteRMSite() throws Exception
+ {
+ usingRestWrapper().processEmptyModel(simpleRequest(
+ DELETE,
+ "sites/rm"
+ ));
+ }
+
+ /**
+ * Update RM site
+ *
+ * @param rmSiteProperties The properties to be updated
+ * @return The updated {@link RMSite}
+ * @throws Exception for the following cases:
+ *
+ * - Api Response code 400 the update request is invalid {@code rmSiteProperties} is invalid
+ * - Api Response code 401 If authentication fails
+ * - Api Response code 403 does not have permission to update {@code RMSite}
+ * - Api Response code 404 {@code RMSite} does not exist
+ * - Api Response code default Unexpected error,model integrity exception
+ *
+ */
+ public RMSite updateRMSite(JsonObject rmSiteProperties) throws Exception
+ {
+ return usingRestWrapper().processModel(RMSite.class, requestWithBody(
+ PUT,
+ rmSiteProperties.toString(),
+ "sites/rm"
+ ));
+ }
+
+}
diff --git a/src/test/java/org/alfresco/rest/BaseRestTest.java b/src/test/java/org/alfresco/rest/BaseRestTest.java
index 7ff9a538e6..522ef3f240 100644
--- a/src/test/java/org/alfresco/rest/BaseRestTest.java
+++ b/src/test/java/org/alfresco/rest/BaseRestTest.java
@@ -13,11 +13,25 @@ package org.alfresco.rest;
import static java.lang.Integer.parseInt;
+import static org.alfresco.com.site.RMSiteCompliance.STANDARD;
+import static org.alfresco.com.site.RMSiteFields.COMPLIANCE;
+import static org.alfresco.com.site.RMSiteFields.DESCRIPTION;
+import static org.alfresco.com.site.RMSiteFields.TITLE;
+import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
+import static org.springframework.http.HttpStatus.CREATED;
+
+import com.google.gson.JsonObject;
import com.jayway.restassured.RestAssured;
+import org.alfresco.dataprep.SiteService;
+import org.alfresco.rest.core.RestWrapper;
+import org.alfresco.rest.requests.RMSiteAPI;
+import org.alfresco.utility.data.DataUser;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
+import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
/**
@@ -32,18 +46,29 @@ import org.testng.annotations.BeforeClass;
@PropertySource(value = "classpath:local.properties", ignoreResourceNotFound = true)
public class BaseRestTest extends RestTest
{
- @Value("${alfresco.rm.scheme}")
+ @Value ("${alfresco.rm.scheme}")
private String scheme;
- @Value("${alfresco.rm.host}")
+ @Value ("${alfresco.rm.host}")
private String host;
- @Value("${alfresco.rm.port}")
+ @Value ("${alfresco.rm.port}")
private String port;
- @Value("${alfresco.rm.basePath}")
+ @Value ("${alfresco.rm.basePath}")
private String basePath;
+ @Autowired
+ public RMSiteAPI rmSiteAPI;
+
+ @Autowired
+ public DataUser dataUser;
+
+ private static final String RM_ID = "rm";
+
+ @Autowired
+ private SiteService siteService;
+
/**
* @see org.alfresco.rest.RestTest#checkServerHealth()
*/
@@ -54,5 +79,43 @@ public class BaseRestTest extends RestTest
RestAssured.baseURI = scheme + "://" + host;
RestAssured.port = parseInt(port);
RestAssured.basePath = basePath;
+ //create RM Site if not exist
+ createRMSiteIfNotExists();
}
-}
+ /**
+ * Helper method to create the RM Site via the POST request
+ * if the site doesn't exist
+ */
+ public void createRMSiteIfNotExists() throws Exception
+ {
+ final String RM_TITLE = "Records Management";
+ final String RM_DESCRIPTION = "Records Management Site";
+ //check RM site doesn't exist
+ if (!siteRMExist())
+ {
+ rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
+ // Build the RM site properties
+ JsonObject rmSiteProperties = buildObject()
+ .add(TITLE, RM_TITLE)
+ .add(DESCRIPTION, RM_DESCRIPTION)
+ .add(COMPLIANCE, STANDARD.toString())
+ .getJson();
+ // Create the RM site
+ rmSiteAPI.createRMSite(rmSiteProperties);
+
+ // Verify the status code
+ rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
+ }
+ }
+
+
+ /**
+ * Check the RM site exist via the GET request
+ */
+ public boolean siteRMExist() throws Exception
+ {
+ RestWrapper restWrapper=rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
+ rmSiteAPI.getSite();
+ return restWrapper.getStatusCode().equals(HttpStatus.OK.toString());
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java
new file mode 100644
index 0000000000..8b22ace9ef
--- /dev/null
+++ b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java
@@ -0,0 +1,155 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * License rights for this program may be obtained from Alfresco Software, Ltd.
+ * pursuant to a written agreement and any use of this program without such an
+ * agreement is prohibited.
+ * #L%
+ */
+package org.alfresco.rest.fileplancomponents;
+
+import static org.alfresco.com.site.RMSiteCompliance.STANDARD;
+import static org.alfresco.com.site.RMSiteFields.COMPLIANCE;
+import static org.alfresco.com.site.RMSiteFields.DESCRIPTION;
+import static org.alfresco.com.site.RMSiteFields.TITLE;
+import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
+import static org.springframework.http.HttpStatus.CONFLICT;
+import static org.springframework.http.HttpStatus.CREATED;
+import static org.springframework.http.HttpStatus.NOT_FOUND;
+import static org.springframework.http.HttpStatus.NO_CONTENT;
+import static org.springframework.http.HttpStatus.OK;
+import static org.springframework.social.alfresco.api.entities.Site.Visibility.PUBLIC;
+import static org.testng.Assert.assertEquals;
+
+import com.google.gson.JsonObject;
+
+import org.alfresco.rest.BaseRestTest;
+import org.alfresco.rest.core.RestWrapper;
+import org.alfresco.rest.model.site.RMSite;
+import org.testng.annotations.Test;
+
+/**
+ * FIXME: Document me :)
+ * FIXME: Should we use dependent tests or not?
+ * They were removed here but there is no guarantee for the test execution order.
+ * In {@link RecordCategoryTest} we create a record category first to delete it.
+ * Probbaly something to think about again.
+ *
+ * @author Rodica Sutu
+ * @since 1.0
+ */
+public class RMSiteTests extends BaseRestTest
+{
+
+ // Constants
+ private static final String RM_ID = "rm";
+ private static final String RM_TITLE = "Records Management";
+ private static final String RM_DESCRIPTION = "Records Management Site";
+
+ @Test
+ (
+ description = "Create RM site as admin user with standard Compliance"
+ )
+ public void createRMSiteAsAdminUser() throws Exception
+ {
+ RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
+ if (siteRMExist())
+ {
+ //Delete the RM site
+ rmSiteAPI.deleteRMSite();
+ }
+ // Build the RM site properties
+ JsonObject rmSiteProperties = buildObject().
+ add(TITLE, RM_TITLE).
+ add(DESCRIPTION, RM_DESCRIPTION).
+ add(COMPLIANCE, STANDARD.toString()).
+ getJson();
+
+ // Create the RM site
+ RMSite rmSite = rmSiteAPI.createRMSite(rmSiteProperties);
+
+ // Verify the status code
+ rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
+
+ // Verify the returned file plan component
+ assertEquals(rmSite.getId(), RM_ID);
+ assertEquals(rmSite.getTitle(), RM_TITLE);
+ assertEquals(rmSite.getDescription(), RM_DESCRIPTION);
+ assertEquals(rmSite.getCompliance(), STANDARD);
+ assertEquals(rmSite.getVisibility(), PUBLIC);
+ }
+
+ @Test
+ (
+ description = "Create RM site when site already exist with admin user"
+ )
+ public void createRMSiteWhenSiteExists() throws Exception
+ {
+ rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
+ createRMSiteIfNotExists();
+ RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
+
+ // Construct new properties
+ String newTitle = RM_TITLE + "createRMSiteWhenSiteExists";
+ String newDescription = RM_DESCRIPTION + "createRMSiteWhenSiteExists";
+
+ // Build the RM site properties
+ JsonObject rmSiteProperties = buildObject().
+ add(TITLE, newTitle).
+ add(DESCRIPTION, newDescription).
+ add(COMPLIANCE, STANDARD.toString()).
+ getJson();
+
+ // Create the RM site
+ rmSiteAPI.createRMSite(rmSiteProperties);
+
+ // Verify the status code
+ restWrapper.assertStatusCodeIs(CONFLICT);
+ }
+
+ @Test
+ (
+ description = "Delete RM site as admin user"
+ )
+ public void deleteRMSite() throws Exception
+ {
+ RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
+
+ // Delete the RM site
+ rmSiteAPI.deleteRMSite();
+
+ // Verify the status code
+ restWrapper.assertStatusCodeIs(NO_CONTENT);
+ }
+
+ @Test
+ (
+ description = "GET RM site as admin user"
+ )
+ public void getRMSite() throws Exception
+ {
+ RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
+
+ // Get the RM site
+ RMSite rmSite=rmSiteAPI.getSite();
+
+ if (!siteRMExist())
+ {
+ // Verify the status code
+ restWrapper.assertStatusCodeIs(NOT_FOUND);
+ }
+ else
+ {
+ // Verify the status code
+ restWrapper.assertStatusCodeIs(OK);
+ assertEquals(rmSite.getId(), RM_ID);
+ assertEquals(rmSite.getDescription(), RM_DESCRIPTION);
+ assertEquals(rmSite.getCompliance(), STANDARD);
+ assertEquals(rmSite.getVisibility(), PUBLIC);
+ }
+
+ }
+}