Merge master into feature/RM-4357_AllowableOperations

This commit is contained in:
Ana Bozianu
2016-11-17 11:04:37 +02:00
54 changed files with 3843 additions and 367 deletions

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>alfresco-rm-automation</artifactId>
<name>Alfresco Records Management Automation</name>
<packaging>pom</packaging>
<parent>
<groupId>org.alfresco</groupId>
@@ -11,43 +11,24 @@
<version>2.6-SNAPSHOT</version>
</parent>
<licenses>
<license>
<name>LGPL 3</name>
</license>
</licenses>
<modules>
<module>rm-automation-community-rest-api</module>
<module>rm-automation-enterprise-rest-api</module>
<module>rm-automation-ui</module>
</modules>
<properties>
<selenium.version>2.45.0</selenium.version>
<spring.version>4.0.5.RELEASE</spring.version>
<maven.build.sourceVersion>1.8</maven.build.sourceVersion>
<suiteXmlFile>testng.xml</suiteXmlFile>
<skip.automationtests>true</skip.automationtests>
<alfresco.installer.host>nightlybuilds</alfresco.installer.host>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-test-source</id>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/unit-test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
<suiteXmlFiles>
<suiteXmlFile>${project.build.testOutputDirectory}/${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<skipTests>${skip.automationtests}</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
@@ -64,15 +45,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<configuration>
<licenseName>alfresco_enterprise</licenseName>
<licenseResolver>file:${project.parent.basedir}/license</licenseResolver>
<descriptionTemplate>${project.parent.basedir}/license/description.ftl</descriptionTemplate>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
@@ -104,88 +76,6 @@
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.alfresco.test</groupId>
<artifactId>dataprep</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.alfresco.test</groupId>
<artifactId>alfresco-testng</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.alfresco</groupId>
<artifactId>selenium-grid</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.htmlelements</groupId>
<artifactId>htmlelements-all</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.properties</groupId>
<artifactId>properties-loader</artifactId>
<version>1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>1.56</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.21</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>install-alfresco</id>
@@ -205,7 +95,7 @@
<echo>Recreating database...</echo>
<sql driver="org.postgresql.Driver" url="jdbc:postgresql:template1" userid="alfresco" password="alfresco" autocommit="true">drop database if exists alfresco; create database alfresco</sql>
<echo>Downloading Alfresco installer...</echo>
<get src="https://nightlybuilds.alfresco.com/${installer.path}" dest="target/alf-installer.bin" />
<get src="https://${alfresco.installer.host}.alfresco.com/${installer.path}" dest="target/alf-installer.bin" />
<chmod file="target/alf-installer.bin" perm="a+x" verbose="true" />
<echo>Installing Alfresco...</echo>
<exec executable="${basedir}/target/alf-installer.bin" dir="target" failonerror="true">
@@ -241,13 +131,13 @@
<artifactItems>
<artifactItem>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-rm-enterprise-share</artifactId>
<artifactId>${alfresco.rm.share}</artifactId>
<version>${project.version}</version>
<type>amp</type>
</artifactItem>
<artifactItem>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-rm-enterprise-repo</artifactId>
<artifactId>${alfresco.rm.repo}</artifactId>
<version>${project.version}</version>
<type>amp</type>
</artifactItem>
@@ -271,7 +161,7 @@
<phase>process-test-resources</phase>
<configuration>
<backup>true</backup>
<ampLocation>${project.build.directory}/amps/alfresco-rm-enterprise-repo-${project.version}.amp</ampLocation>
<ampLocation>${project.build.directory}/amps/${alfresco.rm.repo}-${project.version}.amp</ampLocation>
<warLocation>${project.build.directory}/alf-installation/tomcat/webapps/alfresco.war</warLocation>
</configuration>
</execution>
@@ -283,7 +173,7 @@
<phase>process-test-resources</phase>
<configuration>
<backup>true</backup>
<ampLocation>${project.build.directory}/amps/alfresco-rm-enterprise-share-${project.version}.amp</ampLocation>
<ampLocation>${project.build.directory}/amps/${alfresco.rm.share}-${project.version}.amp</ampLocation>
<warLocation>${project.build.directory}/alf-installation/tomcat/webapps/share.war</warLocation>
</configuration>
</execution>

View File

@@ -0,0 +1,8 @@
/target/
/.settings/
.classpath
.project
/src/test/resources/local.properties
/.idea/
*.iml
/test-output/

View File

@@ -0,0 +1,3 @@
FIXME: Add more info to the README file
In order to change the value of a property in "config.properties" create a file called "local.properties" under src/test/resources and redefine the property with the new value.

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>alfresco-rm-automation-community-rest-api</artifactId>
<name>Alfresco Records Management Automation Community REST API</name>
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-rm-automation</artifactId>
<version>2.6-SNAPSHOT</version>
</parent>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<suiteXmlFile>testng.xml</suiteXmlFile>
<skip.automationtests>true</skip.automationtests>
<alfresco.rm.share>alfresco-rm-community-share</alfresco.rm.share>
<alfresco.rm.repo>alfresco-rm-community-repo</alfresco.rm.repo>
</properties>
<dependencies>
<dependency>
<groupId>org.alfresco.tas</groupId>
<artifactId>restapi-test</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.alfresco.tas</groupId>
<artifactId>restapi-test</artifactId>
<version>1.0-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.jglue.fluent-json</groupId>
<artifactId>fluent-json</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
<suiteXmlFiles>
<suiteXmlFile>${project.build.testOutputDirectory}/${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<skipTests>${skip.automationtests}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,363 @@
/*
* #%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.rm.model.fileplancomponents;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.ALLOWABLE_OPERATIONS;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.IS_CLOSED;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* POJO for file plan component
*
* @author Tuna Aksoy
* @since 2.6
*/
public class FilePlanComponent
{
@JsonProperty (required = true)
private String id;
@JsonProperty (required = true)
private String parentId;
@JsonProperty (required = true)
private String name;
@JsonProperty (required = true)
private String nodeType;
@JsonProperty (required = true)
private boolean isCategory;
@JsonProperty (required = true)
private boolean isRecordFolder;
@JsonProperty (required = true)
private boolean isFile;
@JsonProperty
private boolean hasRetentionSchedule;
@JsonProperty(value = IS_CLOSED)
private boolean isClosed;
@JsonProperty
private boolean isCompleted;
@JsonProperty (required = true)
private List<String> aspectNames;
@JsonProperty (required = true)
private FilePlanComponentUserInfo createdByUser;
@JsonProperty(value = PROPERTIES, required = true)
private FilePlanComponentProperties properties;
@JsonProperty (value = ALLOWABLE_OPERATIONS)
private List<String> allowableOperations;
private FilePlanComponentPath path;
@JsonProperty (required = true)
private String modifiedAt;
@JsonProperty (required = true)
private String createdAt;
@JsonProperty (required = true)
private FilePlanComponentUserInfo modifiedByUser;
/**
* @return the id
*/
public String getId()
{
return this.id;
}
/**
* @param id the id to set
*/
public void setId(String id)
{
this.id = id;
}
/**
* @return the parentId
*/
public String getParentId()
{
return this.parentId;
}
/**
* @param parentId the parentId to set
*/
public void setParentId(String parentId)
{
this.parentId = parentId;
}
/**
* @return the name
*/
public String getName()
{
return this.name;
}
/**
* @param name the name to set
*/
public void setName(String name)
{
this.name = name;
}
/**
* @return the nodeType
*/
public String getNodeType()
{
return this.nodeType;
}
/**
* @param nodeType the nodeType to set
*/
public void setNodeType(String nodeType)
{
this.nodeType = nodeType;
}
/**
* @return the isCategory
*/
public boolean isIsCategory()
{
return this.isCategory;
}
/**
* @param isCategory the isCategory to set
*/
public void setCategory(boolean isCategory)
{
this.isCategory = isCategory;
}
/**
* @return the isRecordFolder
*/
public boolean isIsRecordFolder()
{
return this.isRecordFolder;
}
/**
* @param isRecordFolder the isRecordFolder to set
*/
public void setRecordFolder(boolean isRecordFolder)
{
this.isRecordFolder = isRecordFolder;
}
/**
* @return the isFile
*/
public boolean isIsFile()
{
return this.isFile;
}
/**
* @param isFile the isFile to set
*/
public void setFile(boolean isFile)
{
this.isFile = isFile;
}
/**
* @return the hasRetentionSchedule
*/
public boolean isHasRetentionSchedule()
{
return this.hasRetentionSchedule;
}
/**
* @param hasRetentionSchedule the hasRetentionSchedule to set
*/
public void setHasRetentionSchedule(boolean hasRetentionSchedule)
{
this.hasRetentionSchedule = hasRetentionSchedule;
}
/**
* @return the properties
*/
public FilePlanComponentProperties getProperties()
{
return properties;
}
/**
* @param properties the properties to set
*/
public void setProperties(FilePlanComponentProperties properties)
{
this.properties = properties;
}
/**
* @return the aspectNames
*/
public List<String> getAspectNames()
{
return this.aspectNames;
}
/**
* @param aspectNames the aspectNames to set
*/
public void setAspectNames(List<String> aspectNames)
{
this.aspectNames = aspectNames;
}
/**
* @return the createdByUser
*/
public FilePlanComponentUserInfo getCreatedByUser()
{
return this.createdByUser;
}
/**
* @param createdByUser the createdByUser to set
*/
public void setCreatedByUser(FilePlanComponentUserInfo createdByUser)
{
this.createdByUser = createdByUser;
}
/**
* @return the allowableOperations
*/
public List<String> getAllowableOperations()
{
return this.allowableOperations;
}
/**
* @return the path
*/
public FilePlanComponentPath getPath()
{
return this.path;
}
/**
* @param path the path to set
*/
public void setPath(FilePlanComponentPath path)
{
this.path = path;
}
/**
* @param modifiedAt the modifiedAt to set
*/
public void setModifiedAt(String modifiedAt)
{
this.modifiedAt = modifiedAt;
}
/**
* @param createdAt the createdAt to set
*/
public void setCreatedAt(String createdAt)
{
this.createdAt = createdAt;
}
/**
* @param modifiedByUser the modifiedByUser to set
*/
public void setModifiedByUser(FilePlanComponentUserInfo modifiedByUser)
{
this.modifiedByUser = modifiedByUser;
}
/**
* @return the modifiedAt
*/
public String getModifiedAt()
{
return this.modifiedAt;
}
/**
* @return the createdAt
*/
public String getCreatedAt()
{
return this.createdAt;
}
/**
* @return the modifiedByUser
*/
public FilePlanComponentUserInfo getModifiedByUser()
{
return this.modifiedByUser;
}
/**
* @return the isClosed
*/
public boolean isClosed()
{
return this.isClosed;
}
/**
* @param closed the isClosed to set
*/
public void setClosed(boolean closed)
{
this.isClosed = closed;
}
/**
* @return the isCompleted
*/
public boolean isCompleted()
{
return this.isCompleted;
}
/**
* @param completed the isCompleted to set
*/
public void setCompleted(boolean completed)
{
this.isCompleted = completed;
}
}

View File

@@ -0,0 +1,68 @@
/*
* #%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.rm.model.fileplancomponents;
import static org.alfresco.rest.rm.util.ParameterCheck.mandatoryString;
/**
* File plan component alias enumeration
*
* @author Tuna Aksoy
* @since 2.6
*/
public enum FilePlanComponentAlias
{
FILE_PLAN_ALIAS("-filePlan-"),
TRANSFERS_ALIAS("-transfers-"),
UNFILED_RECORDS_CONTAINER_ALIAS("-unfiled-"),
HOLDS_ALIAS("-holds-");
private String alias;
private FilePlanComponentAlias(String alias)
{
this.alias = alias;
}
public static final FilePlanComponentAlias getFilePlanComponentAlias(String alias)
{
mandatoryString("alias", alias);
FilePlanComponentAlias result = null;
FilePlanComponentAlias[] values = values();
for (FilePlanComponentAlias filePlanComponentAlias : values)
{
if (filePlanComponentAlias.toString().equals(alias))
{
result = filePlanComponentAlias;
break;
}
}
if (result == null)
{
throw new IllegalArgumentException("Invalid file plan component alias enum value: '" + alias + "'.");
}
return result;
}
/**
* @see java.lang.Enum#toString()
*/
@Override
public String toString()
{
return this.alias;
}
}

View File

@@ -0,0 +1,35 @@
/*
* #%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.rm.model.fileplancomponents;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.ENTRY;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.alfresco.rest.core.RestModels;
/**
* POJO for file plan component entry
*
* @author Tuna Aksoy
* @since 2.6
*/
public class FilePlanComponentEntry extends RestModels<FilePlanComponent, FilePlanComponentEntry>
{
@JsonProperty(ENTRY)
FilePlanComponent filePlanComponent;
public FilePlanComponent getFilePlanComponent()
{
return filePlanComponent;
}
}

View File

@@ -0,0 +1,36 @@
/*
* #%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.rm.model.fileplancomponents;
/**
* File plan component field names constants
*
* @author Tuna Aksoy
* @since 2.6
*/
public class FilePlanComponentFields
{
public static final String NAME = "name";
public static final String NODE_TYPE = "nodeType";
public static final String NODE_PARENT_ID = "parentId";
public static final String ENTRY = "entry";
public static final String PROPERTIES = "properties";
public static final String PROPERTIES_TITLE = "cm:title";
public static final String PROPERTIES_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator";
public static final String PROPERTIES_HOLD_REASON = "rma:holdReason";
public static final String PROPERTIES_DESCRIPTION = "cm:description";
public static final String PROPERTIES_SUPPLEMENTAL_MARKING_LIST = "rmc:supplementalMarkingList";
public static final String ALLOWABLE_OPERATIONS = "allowableOperations";
public static final String IS_CLOSED="isclosed";
public static final String PROPERTIES_REVIEW_PERIOD="rma:reviewPeriod";
public static final String PROPERTIES_LOCATION="rma:location";
}

View File

@@ -0,0 +1,56 @@
/*
* #%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.rm.model.fileplancomponents;
/**
* POJO for id/name pair
*
* @author Kristijan Conkas
* @since 2.6
*/
public class FilePlanComponentIdNamePair
{
public String id;
public String name;
/**
* @return the id
*/
public String getId()
{
return this.id;
}
/**
* @param id the id to set
*/
public void setId(String id)
{
this.id = id;
}
/**
* @return the name
*/
public String getName()
{
return this.name;
}
/**
* @param name the name to set
*/
public void setName(String name)
{
this.name = name;
}
}

View File

@@ -0,0 +1,78 @@
/*
* #%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.rm.model.fileplancomponents;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* POJO for FilePlanComponent path parameter
* <br>
* @author Kristijan Conkas
* @since 2.6
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class FilePlanComponentPath
{
private String name;
private boolean isComplete;
private List<FilePlanComponentIdNamePair> elements;
/**
* @return the name
*/
public String getName()
{
return this.name;
}
/**
* @param name the name to set
*/
public void setName(String name)
{
this.name = name;
}
/**
* @return the isComplete
*/
public boolean isComplete()
{
return this.isComplete;
}
/**
* @param isComplete the isComplete to set
*/
public void setComplete(boolean isComplete)
{
this.isComplete = isComplete;
}
/**
* @return the elements
*/
public List<FilePlanComponentIdNamePair> getElements()
{
return this.elements;
}
/**
* @param elements the elements to set
*/
public void setElements(List<FilePlanComponentIdNamePair> elements)
{
this.elements = elements;
}
}

View File

@@ -0,0 +1,171 @@
/*
* #%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.rm.model.fileplancomponents;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_HOLD_REASON;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_LOCATION;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_REVIEW_PERIOD;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SUPPLEMENTAL_MARKING_LIST;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* POJO for file plan component properties
*
* @author Kristijan Conkas
* @since 2.6
*/
//FIXME: Once the fields have been added the JsonIgnoreProperties annotation should be removed
@JsonIgnoreProperties (ignoreUnknown = true)
public class FilePlanComponentProperties
{
@JsonProperty(PROPERTIES_VITAL_RECORD_INDICATOR)
private boolean vitalRecord;
@JsonProperty(PROPERTIES_TITLE)
private String title;
@JsonProperty(PROPERTIES_HOLD_REASON)
private String holdReason;
@JsonProperty(PROPERTIES_DESCRIPTION)
private String description;
@JsonProperty(PROPERTIES_SUPPLEMENTAL_MARKING_LIST)
private List<String> supplementalMarkingList;
@JsonProperty(PROPERTIES_REVIEW_PERIOD)
private ReviewPeriod reviewPeriod;
@JsonProperty(PROPERTIES_LOCATION)
private String location;
/**
* @return the vitalRecord
*/
public boolean isVitalRecord()
{
return this.vitalRecord;
}
/**
* @param vitalRecord the vitalRecord to set
*/
public void setVitalRecord(boolean vitalRecord)
{
this.vitalRecord = vitalRecord;
}
/**
* @return the title
*/
public String getTitle()
{
return this.title;
}
/**
* @param title the title to set
*/
public void setTitle(String title)
{
this.title = title;
}
/**
* @return the holdReason
*/
public String getHoldReason()
{
return this.holdReason;
}
/**
* @param holdReason the holdReason to set
*/
public void setHoldReason(String holdReason)
{
this.holdReason = holdReason;
}
/**
* @param description the description to set
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* @return the description
*/
public String getDescription()
{
return this.description;
}
/**
* @return the supplementalMarkingList
*/
public List<String> getSupplementalMarkingList()
{
return this.supplementalMarkingList;
}
/**
* @param supplementalMarkingList the supplementalMarkingList to set
*/
public void setSupplementalMarkingList(List<String> supplementalMarkingList)
{
this.supplementalMarkingList = supplementalMarkingList;
}
/**
* @return the reviewPeriod
*/
public ReviewPeriod getReviewPeriod()
{
return reviewPeriod;
}
/**
* @param reviewPeriod the reviewPeriod to set
*/
public void setReviewPeriod(ReviewPeriod reviewPeriod)
{
this.reviewPeriod = reviewPeriod;
}
/**
* @return the location
*/
public String getLocation()
{
return location;
}
/**
* @param location the location to set
*/
public void setLocation(String location)
{
this.location = location;
}
}

View File

@@ -0,0 +1,72 @@
/*
* #%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.rm.model.fileplancomponents;
import static org.alfresco.rest.rm.util.ParameterCheck.mandatoryString;
/**
* File plan component type enumeration
*
* @author Tuna Aksoy
* @since 2.6
*/
public enum FilePlanComponentType
{
FILE_PLAN_TYPE("rma:filePlan"),
RECORD_CATEGORY_TYPE("rma:recordCategory"),
RECORD_FOLDER_TYPE("rma:recordFolder"),
HOLD_TYPE("rma:hold"),
UNFILED_RECORD_FOLDER_TYPE("rma:unfiledRecordFolder"),
HOLD_CONTAINER_TYPE("rma:holdContainer"),
TRANSFER_CONTAINER_TYPE("rma:transferContainer"),
UNFILED_CONTAINER_TYPE("rma:unfiledRecordContainer");
private String type;
private FilePlanComponentType(String type)
{
this.type = type;
}
public static final FilePlanComponentType getFilePlanComponentType(String type)
{
mandatoryString("type", type);
FilePlanComponentType result = null;
FilePlanComponentType[] values = values();
for (FilePlanComponentType filePlanComponentType : values)
{
if (filePlanComponentType.toString().equals(filePlanComponentType))
{
result = filePlanComponentType;
break;
}
}
if (result == null)
{
throw new IllegalArgumentException("Invalid file plan component type enum value: '" + type + "'.");
}
return result;
}
/**
* @see java.lang.Enum#toString()
*/
@Override
public String toString()
{
return this.type;
}
}

View File

@@ -0,0 +1,56 @@
/*
* #%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.rm.model.fileplancomponents;
/**
* POJO for file plan component created by object
*
* @author Kristijan Conkas
* @since 2.6
*/
public class FilePlanComponentUserInfo
{
private String id;
private String displayName;
/**
* @return the id
*/
public String getId()
{
return this.id;
}
/**
* @param id the id to set
*/
public void setId(String id)
{
this.id = id;
}
/**
* @return the displayName
*/
public String getDisplayName()
{
return this.displayName;
}
/**
* @param displayName the displayName to set
*/
public void setDisplayName(String displayName)
{
this.displayName = displayName;
}
}

View File

@@ -0,0 +1,25 @@
/*
* #%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.rm.model.fileplancomponents;
import org.alfresco.rest.core.RestModels;
/**
* Handle collection of FilePlanComponents
*
* @author Kristijan Conkas
* @since 2.6
*/
public class FilePlanComponentsCollection extends RestModels<FilePlanComponentEntry, FilePlanComponentsCollection>
{
}

View File

@@ -0,0 +1,45 @@
package org.alfresco.rest.rm.model.fileplancomponents;
/**
* POJO for the review period
*
* @author Rodica Sutu
* @since 2.6
*/
public class ReviewPeriod
{
private String periodType;
private String expression;
/**
* @return the periodType
*/
public String getPeriodType()
{
return this.periodType;
}
/**
* @param periodType the periodType to set
*/
public void setPeriodType(String periodType)
{
this.periodType = periodType;
}
/**
* @return the expression
*/
public String getExpression()
{
return this.expression;
}
/**
* @param expression the expression to set
*/
public void setExpression(String expression)
{
this.expression = expression;
}
}

View File

@@ -0,0 +1,48 @@
/*
* #%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.rm.model.site;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.alfresco.rest.model.RestSiteModel;
/**
* POJO for RM Site component
*
* @author Rodica Sutu
* @since 2.6
*/
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;
}
}

View File

@@ -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.rest.rm.model.site;
/**
* RM Site compliance
*
* @author Tuna Aksoy
* @since 2.6
*/
public enum RMSiteCompliance
{
STANDARD,
DOD5015
}

View File

@@ -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.rest.rm.model.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 2.6
*/
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";
}

View File

@@ -0,0 +1,169 @@
/*
* #%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.rm.requests;
import static org.alfresco.rest.core.RestRequest.requestWithBody;
import static org.alfresco.rest.core.RestRequest.simpleRequest;
import static org.alfresco.rest.rm.util.ParameterCheck.mandatoryObject;
import static org.alfresco.rest.rm.util.ParameterCheck.mandatoryString;
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.rm.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentsCollection;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* File plan component REST API Wrapper
*
* @author Tuna Aksoy
* @author Kristijan Conkas
* @since 2.6
*/
@Component
@Scope(value = "prototype")
public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
{
/**
* Get a file plan component
*
* @param filePlanComponentId The id of the file plan component to get
* @return The {@link FilePlanComponent} for the given file plan component id
* @throws Exception for the following cases:
* <ul>
* <li>{@code fileplanComponentId} is not a valid format</li>
* <li>authentication fails</li>
* <li>{@code fileplanComponentId} does not exist</li>
* </ul>
*/
public FilePlanComponent getFilePlanComponent(String filePlanComponentId) throws Exception
{
mandatoryString("filePlanComponentId", filePlanComponentId);
return usingRestWrapper().processModel(FilePlanComponent.class, simpleRequest(
GET,
"fileplan-components/{fileplanComponentId}?{parameters}",
filePlanComponentId, getParameters()
));
}
/**
* List child components of a file plan component
*
* @param filePlanComponentId The id of the file plan component of which to get child components
* @return The {@link FilePlanComponent} for the given file plan component id
* @throws Exception for the following cases:
* <ul>
* <li>{@code fileplanComponentId} is not a valid format</li>
* <li>authentication fails</li>
* <li>{@code fileplanComponentId} does not exist</li>
* </ul>
*/
public FilePlanComponentsCollection listChildComponents(String filePlanComponentId) throws Exception
{
mandatoryString("filePlanComponentId", filePlanComponentId);
return usingRestWrapper().processModels(FilePlanComponentsCollection.class, simpleRequest(
GET,
"fileplan-components/{fileplanComponentId}/children",
filePlanComponentId
));
}
/**
* Creates a file plan component with the given properties under the parent node with the given id
*
* @param filePlanComponentProperties The properties of the file plan component to be created
* @param parentId The id of the parent where the new file plan component should be created
* @return The {@link FilePlanComponent} with the given properties
* @throws Exception for the following cases:
* <ul>
* <li>{@code fileplanComponentId} is not a valid format</li>
* <li>authentication fails</li>
* <li>current user does not have permission to add children to {@code fileplanComponentId}</li>
* <li>{@code fileplanComponentId} does not exist</li>
* <li>new name clashes with an existing node in the current parent container</li>
* <li>model integrity exception, including node name with invalid characters</li>
* </ul>
*/
public FilePlanComponent createFilePlanComponent(JsonObject filePlanComponentProperties, String parentId) throws Exception
{
mandatoryObject("filePlanComponentProperties", filePlanComponentProperties);
mandatoryString("parentId", parentId);
return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody(
POST,
filePlanComponentProperties.toString(),
"fileplan-components/{fileplanComponentId}/children",
parentId
));
}
/**
* Updates a file plan component
*
* @param filePlanComponentProperties The properties to be updated
* @param filePlanComponentId The id of the file plan component which will be updated
* @param returns The updated {@link FilePlanComponent}
* @throws Exception for the following cases:
* <ul>
* <li>the update request is invalid or {@code fileplanComponentId} is not a valid format or {@code filePlanComponentProperties} is invalid</li>
* <li>authentication fails</li>
* <li>current user does not have permission to update {@code fileplanComponentId}</li>
* <li>{@code fileplanComponentId} does not exist</li>
* <li>the updated name clashes with an existing node in the current parent folder</li>
* <li>model integrity exception, including node name with invalid characters</li>
* </ul>
*/
public FilePlanComponent updateFilePlanComponent(JsonObject filePlanComponentProperties, String filePlanComponentId) throws Exception
{
mandatoryObject("filePlanComponentProperties", filePlanComponentProperties);
mandatoryString("filePlanComponentId", filePlanComponentId);
return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody(
PUT,
filePlanComponentProperties.toString(),
"fileplan-components/{fileplanComponentId}",
filePlanComponentId
));
}
/**
* Delete file plan component
*
* @param filePlanComponentId The id of the file plan component to be deleted
* @throws Exception for the following cases:
* <ul>
* <li>{@code fileplanComponentId} is not a valid format</li>
* <li>authentication fails</li>
* <li>current user does not have permission to delete {@code fileplanComponentId}</li>
* <li>{@code fileplanComponentId} does not exist</li>
* <li>{@code fileplanComponentId} is locked and cannot be deleted</li>
* </ul>
*/
public void deleteFilePlanComponent(String filePlanComponentId) throws Exception
{
mandatoryString("filePlanComponentId", filePlanComponentId);
usingRestWrapper().processEmptyModel(simpleRequest(
DELETE,
"fileplan-components/{fileplanComponentId}",
filePlanComponentId
));
}
}

View File

@@ -0,0 +1,127 @@
/*
* #%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.rm.requests;
import static org.alfresco.rest.core.RestRequest.requestWithBody;
import static org.alfresco.rest.core.RestRequest.simpleRequest;
import static org.alfresco.rest.rm.util.ParameterCheck.mandatoryObject;
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.rm.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 2.6
*/
@Component
@Scope (value = "prototype")
public class RMSiteAPI extends RestAPI<RMSiteAPI>
{
/**
* Get the RM site
*
* @return The {@link RMSite} for the given file plan component id
* @throws Exception for the following cases:
* <ul>
* <li>Api Response code 400 Invalid parameter: GET request is supported only for the RM site</li>
* <li>Api Response code 401 If authentication failed</li>
* <li>Api Response code 409 If RM Site does not exist</li>
* <li>Api Response code default Unexpected error</li>
* </ul>
*/
public RMSite getSite() throws Exception
{
return usingRestWrapper().processModel(RMSite.class, simpleRequest(
GET,
"ig-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:
* <ul>
* <li>Api Response code 400 Invalid parameter: title, or description exceed the maximum length; or siteBodyCreate invalid</li>
* <li>Api Response code 401 If authentication failed</
* <li>Api Response code 409 RM Site already exists</li>
* <li>Api Response code default Unexpected error</li>
* </ul>
*/
public RMSite createRMSite(JsonObject rmSiteProperties) throws Exception
{
mandatoryObject("rmSiteProperties", rmSiteProperties);
return usingRestWrapper().processModel(RMSite.class, requestWithBody(
POST,
rmSiteProperties.toString(),
"ig-sites"
));
}
/**
* Delete RM site
* @throws Exception for the following cases:
* <ul>
* <li>Api Response code 400 Invalid parameter: DELETE request is supported only for the RM site</li>
* <li>Api Response code 401 If authentication failed</
* <li>Api Response code 403 Current user does not have permission to delete the site that is visible to them.</li>
* <li>Api Response code 404 RM site does not exist</li>
* <li>Api Response code default Unexpected error</li>
* </ul>
*/
public void deleteRMSite() throws Exception
{
usingRestWrapper().processEmptyModel(simpleRequest(
DELETE,
"ig-sites/rm"
));
}
/**
* Update RM site
*
* @param rmSiteProperties The properties to be updated
* @return The updated {@link RMSite}
* @throws Exception for the following cases:
* <ul>
* <li>Api Response code 400 the update request is invalid {@code rmSiteProperties} is invalid</li>
* <li>Api Response code 401 If authentication fails</li>
* <li>Api Response code 403 does not have permission to update {@code RMSite}</li>
* <li>Api Response code 404 {@code RMSite} does not exist</li>
* <li>Api Response code default Unexpected error,model integrity exception</li>
* </ul>
*/
public RMSite updateRMSite(JsonObject rmSiteProperties) throws Exception
{
mandatoryObject("rmSiteProperties", rmSiteProperties);
return usingRestWrapper().processModel(RMSite.class, requestWithBody(
PUT,
rmSiteProperties.toString(),
"ig-sites/rm"
));
}
}

View File

@@ -0,0 +1,58 @@
/*
* #%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.rm.util;
import static org.apache.commons.lang3.StringUtils.isBlank;
/**
* Utility class for checking parameters
*
* @author Tuna Aksoy
* @since 2.6
*/
public class ParameterCheck
{
private ParameterCheck()
{
// Intentionally blank
}
/**
* Checks if a given {@link String} is blank or not, i.e. not <code>null<code>, "" or " ".
*
* @param paramName The name of the parameter to check
* @param paramValue The value of the parameter to check
* @throws IllegalArgumentException Throws an exception if the given value is blank
*/
public static void mandatoryString(final String paramName, final String paramValue) throws IllegalArgumentException
{
if (isBlank(paramValue))
{
throw new IllegalArgumentException("'" + paramName + "' is a mandatory parameter.");
}
}
/**
* Checks if a given {@link Object} is null or not
*
* @param paramName The name of the parameter to check
* @param object The value of the parameter to check
* @throws IllegalArgumentException Throws an exception if the given value is null
*/
public static void mandatoryObject(final String paramName, final Object object) throws IllegalArgumentException
{
if (object == null)
{
throw new IllegalArgumentException("'" + paramName + "' is a mandatory parameter.");
}
}
}

View File

@@ -0,0 +1,25 @@
/*
* #%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.rm.base;
/**
* List of allowable operations
*
* @author Tuna Aksoy
* @since 2.6
*/
public class AllowableOperations
{
public static final String CREATE = "create";
public static final String UPDATE = "update";
public static final String DELETE = "delete";
}

View File

@@ -0,0 +1,192 @@
/*
* #%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.rm.base;
import static java.lang.Integer.parseInt;
import static org.alfresco.rest.rm.base.TestData.CATEGORY_TITLE;
import static org.alfresco.rest.rm.base.TestData.FOLDER_TITLE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NAME;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.model.site.RMSiteCompliance.STANDARD;
import static org.alfresco.rest.rm.model.site.RMSiteFields.COMPLIANCE;
import static org.alfresco.rest.rm.model.site.RMSiteFields.DESCRIPTION;
import static org.alfresco.rest.rm.model.site.RMSiteFields.TITLE;
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;
import com.google.gson.JsonObject;
import com.jayway.restassured.RestAssured;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.rm.requests.FilePlanComponentAPI;
import org.alfresco.rest.rm.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.testng.annotations.BeforeClass;
/**
* Base class for all IG REST API Tests
*
* @author Kristijan Conkas
* @author Tuna Aksoy
* @since 2.6
*/
@Configuration
@PropertySource("classpath:default.properties")
@PropertySource(value = "classpath:local.properties", ignoreResourceNotFound = true)
public class BaseRestTest extends RestTest
{
@Value ("${alfresco.scheme}")
private String scheme;
@Value ("${alfresco.server}")
private String server;
@Value ("${alfresco.port}")
private String port;
@Value ("${rest.rmPath}")
private String restRmPath;
@Value ("${rest.basePath}")
private String restCorePath;
@Autowired
private RMSiteAPI rmSiteAPI;
@Autowired
private DataUser dataUser;
@Autowired
public FilePlanComponentAPI filePlanComponentAPI;
// Constants
public static final String RM_ID = "rm";
public static final String RM_TITLE = "Records Management";
public static final String RM_DESCRIPTION = "Records Management Site";
/**
* @see org.alfresco.rest.RestTest#checkServerHealth()
*/
@Override
@BeforeClass (alwaysRun = true)
public void checkServerHealth() throws Exception
{
RestAssured.baseURI = scheme + "://" + server;
RestAssured.port = parseInt(port);
RestAssured.basePath = restRmPath;
// 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
{
// Check RM site doesn't exist
if (!siteRMExists())
{
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 if the RM site exists via the GET request
*/
public boolean siteRMExists() throws Exception
{
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
rmSiteAPI.getSite();
return restWrapper.getStatusCode().equals(OK.toString());
}
/**
* Helper method to create child category
*
* @param parentCategoryId The id of the parent category
* @param categoryName The name of the category
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
{
return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE, CATEGORY_TITLE);
}
/**
* Helper method to create child folder
*
* @param parentCategoryId The id of the parent category
* @param folderName The name of the category
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createFolder(String parentCategoryId, String folderName) throws Exception
{
return createComponent(parentCategoryId, folderName, RECORD_FOLDER_TYPE, FOLDER_TITLE);
}
/**
* Helper method to create generic child component
*
* @param parentComponentId The id of the parent file plan component
* @param componentName The name of the file plan component
* @param componentType The name of the file plan component
* @param componentTitle
* @return The created file plan component
* @throws Exception
*/
private FilePlanComponent createComponent(String parentComponentId, String componentName, FilePlanComponentType componentType, String componentTitle) throws Exception
{
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
JsonObject componentProperties = buildObject().add(NAME, componentName)
.add(NODE_TYPE, componentType.toString())
.addObject(PROPERTIES)
.add(PROPERTIES_TITLE, componentTitle)
.end()
.getJson();
FilePlanComponent fpc = filePlanComponentAPI.createFilePlanComponent(componentProperties, parentComponentId);
restWrapper.assertStatusCodeIs(CREATED);
return fpc;
}
}

View File

@@ -0,0 +1,101 @@
/*
* #%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.rm.base;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import org.testng.annotations.DataProvider;
/**
* Test data used in tests
*
* @author Rodica Sutu
* @since 2.6
*/
public interface TestData
{
/**
* A user with ALFRESCO_ADMINISTRATORS role.
* <p>"GROUP_ANOTHER_ADMIN_EXISTS" The ANOTHER_ADMIN user has been created.
*/
public static final String ANOTHER_ADMIN = "another_admin";
/**
* The default password used when creating test users.
*/
public static final String DEFAULT_PASSWORD = "password";
/**
* The default email address used when creating test users.
*/
public static final String DEFAULT_EMAIL = "default@alfresco.com";
/**
* Data Provider with the special file plan components alias
* @return file plan component alias
*/
@DataProvider
public static Object[][] getContainers()
{
return new Object[][] {
{ FILE_PLAN_ALIAS.toString() },
{ TRANSFERS_ALIAS.toString() },
{ HOLDS_ALIAS.toString() },
{ UNFILED_RECORDS_CONTAINER_ALIAS.toString() },
};
}
/**
* Data Provider with:
* the special file plan components alias
* file plan component node type
* @return file plan component alias
*/
@DataProvider
public static Object[][] getContainersAndTypes()
{
return new Object[][] {
{ FILE_PLAN_ALIAS, FILE_PLAN_TYPE },
{ TRANSFERS_ALIAS, TRANSFER_CONTAINER_TYPE },
{ HOLDS_ALIAS, HOLD_CONTAINER_TYPE },
{ UNFILED_RECORDS_CONTAINER_ALIAS, UNFILED_CONTAINER_TYPE },
};
}
/**
* The default CATEGORY name used when creating categories
*/
public static String CATEGORY_NAME = "CATEGORY NAME"+ getRandomAlphanumeric();
/**
* The default CATEGORY title used when creating categories
*/
public static String CATEGORY_TITLE = "CATEGORY TITLE" + getRandomAlphanumeric();
/**
* The default FOLDER name used when creating categories
*/
public static String FOLDER_NAME = "FOLDER NAME" + getRandomAlphanumeric();
/**
* The default FOLDER title used when creating categories
*/
public static String FOLDER_TITLE = "FOLDER TITLE" + getRandomAlphanumeric();
}

View File

@@ -0,0 +1,303 @@
/*
* #%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.rm.fileplancomponents;
import static java.util.Arrays.asList;
import static org.alfresco.rest.rm.base.AllowableOperations.CREATE;
import static org.alfresco.rest.rm.base.AllowableOperations.DELETE;
import static org.alfresco.rest.rm.base.AllowableOperations.UPDATE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NAME;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
import static org.springframework.http.HttpStatus.FORBIDDEN;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import com.google.gson.JsonObject;
import org.alfresco.rest.rm.base.BaseRestTest;
import org.alfresco.rest.rm.base.TestData;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.rm.requests.FilePlanComponentAPI;
import org.alfresco.rest.rm.requests.RMSiteAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.report.Bug;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.Test;
/**
* This class contains the tests for
* the File Plan CRUD API
*
* @author Rodica Sutu
* @since 2.6
*/
public class FilePlanTests extends BaseRestTest
{
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private RMSiteAPI rmSiteAPI;
@Autowired
private DataUser dataUser;
/**
* Given that the RM site doesn't exist
* When I use the API to get the File Plan/Holds/Unfiled Records Container/Transfers
* Then I get the 404 response code
*/
@Test
(
description = "Check the GET response code when the RM site doesn't exist",
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
public void getFilePlanComponentWhenRMIsNotCreated(String filePlanAlias) throws Exception
{
// Check RM Site Exist
if (siteRMExists())
{
// Delete RM Site
rmSiteAPI.deleteRMSite();
}
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Get the file plan component
filePlanComponentAPI.getFilePlanComponent(filePlanAlias.toString());
//check the response code is NOT_FOUND
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND);
}
/**
* Given that a file plan exists
* When I ask the API for the details of the file plan
* Then I am given the details of the file plan
*/
@Test
(
description = "Check the GET response for special file plan components when the RM site exit",
dataProviderClass = TestData.class,
dataProvider = "getContainersAndTypes"
)
public void getFilePlanComponentWhenRMIsCreated(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Get the file plan special container
FilePlanComponent filePlanComponent = filePlanComponentAPI.getFilePlanComponent(filePlanAlias.toString());
// Check the response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK);
// Check the response contains the right node type
assertEquals(filePlanComponent.getNodeType(), rmType.toString());
}
/**
* Given that a file plan exists
* When I ask the API for the details of the file plan to include the allowableOperations property
* Then I am given the allowableOperations property with the update and create operations.
*/
@Test
(
description = "Check the allowableOperations list returned ",
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
public void includeAllowableOperations(String specialContainerAlias) throws Exception
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Get the file plan special containers with the optional parameter allowableOperations
FilePlanComponent filePlanComponent = filePlanComponentAPI.withParams("include=allowableOperations").getFilePlanComponent(specialContainerAlias);
// Check the list of allowableOperations returned
assertTrue(filePlanComponent.getAllowableOperations().containsAll(asList(UPDATE, CREATE)),
"Wrong list of the allowable operations is return" + filePlanComponent.getAllowableOperations().toString());
// Check the list of allowableOperations doesn't contains DELETE operation
assertFalse(filePlanComponent.getAllowableOperations().contains(DELETE),
"The list of allowable operations contains delete option" + filePlanComponent.getAllowableOperations().toString());
}
/**
* Given that a file plan exists
* When I ask the API to modify the details of the file plan
* Then the details of the file are modified
* Note: the details of the file plan are limited to title and description.
*/
@Test
@Bug (id = "RM-4295")
public void updateFilePlan() throws Exception
{
String FILE_PLAN_DESCRIPTION = "Description updated " + getRandomAlphanumeric();
String FILE_PLAN_TITLE = "Title updated " + getRandomAlphanumeric();
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Build the file plan root properties
JsonObject filePlanProperties = buildObject()
.addObject(PROPERTIES)
.add(PROPERTIES_TITLE, FILE_PLAN_TITLE)
.add(PROPERTIES_DESCRIPTION, FILE_PLAN_DESCRIPTION)
.end()
.getJson();
// Update the record category
FilePlanComponent renamedFilePlanComponent = filePlanComponentAPI.updateFilePlanComponent(filePlanProperties,FILE_PLAN_ALIAS.toString());
// Verify the response status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK);
// Verify the returned description field for the file plan component
assertEquals(renamedFilePlanComponent.getProperties().getDescription(), FILE_PLAN_DESCRIPTION);
// Verify the returned title field for the file plan component
assertEquals(renamedFilePlanComponent.getProperties().getTitle(), FILE_PLAN_TITLE);
}
/**
* Given that a file plan exists
* When I ask the API to delete the file plan
* Then the 403 response code is returned.
*/
@Test
(
description = "Check the response code when deleting the special file plan components",
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
public void deleteFilePlanSpecialComponents(String filePlanAlias) throws Exception
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Delete the file plan component
filePlanComponentAPI.deleteFilePlanComponent(filePlanAlias.toString());
// Check the DELETE response status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
}
/**
* Given that RM site exists
* When I ask to create the file plan
* Then the 403 response code is returned.
*/
@Test
(
description = "Check the response code when creating the special file plan components",
dataProviderClass = TestData.class,
dataProvider = "getContainersAndTypes"
)
@Bug(id="RM-4296")
public void createFilePlanSpecialContainerWhenExists(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Get the RM site ID
String rmSiteId = rmSiteAPI.getSite().getGuid();
String name = filePlanAlias + getRandomAlphanumeric();
// Build the file plan root properties
JsonObject componentProperties = buildObject()
.add(NAME, name)
.add(NODE_TYPE, rmType.toString())
.getJson();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create the special containers into RM site - parent folder
filePlanComponentAPI.createFilePlanComponent(componentProperties, rmSiteId);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
// Create the special containers into RM site - parent folder
filePlanComponentAPI.createFilePlanComponent(componentProperties, FILE_PLAN_ALIAS.toString());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
// Create the special containers into the root of special containers containers
filePlanComponentAPI.createFilePlanComponent(componentProperties, filePlanAlias.toString());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
/**
* Given that RM site exists
* When a non-RM user ask the API for the details of the file plan
* Then the status code 403 (Permission denied) is return
*/
@Test
(
description = "Check the response code when the RM site containers are get with non rm users",
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
public void getSpecialFilePlanComponentsWithNonRMuser(String filePlanAlias) throws Exception
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Disconnect user from REST API session
rmSiteAPI.usingRestWrapper().disconnect();
// Authenticate admin user to Alfresco REST API
restClient.authenticateUser(dataUser.getAdminUser());
// Create a random user
UserModel nonRMuser = dataUser.createRandomTestUser("testUser");
// Authenticate using the random user
filePlanComponentAPI.usingRestWrapper().authenticateUser(nonRMuser);
// Get the special file plan components
filePlanComponentAPI.getFilePlanComponent(filePlanAlias.toString());
// Check the response status code is FORBIDDEN
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
}
}

View File

@@ -0,0 +1,374 @@
/*
* #%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.rm.fileplancomponents;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NAME;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
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.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import com.google.gson.JsonObject;
import org.alfresco.rest.rm.base.BaseRestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.rm.requests.FilePlanComponentAPI;
import org.alfresco.utility.data.DataUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.Test;
/**
* Record category related API tests
*
* @author Kristijan Conkas
* @author Tuna Aksoy
* @since 2.6
*/
public class RecordCategoryTest extends BaseRestTest
{
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private DataUser dataUser;
// Number of children (for children creation test)
private static final int NUMBER_OF_CHILDREN = 10;
/**
* <pre>
* Given that a file plan exists
* When I ask the API to create a root record category
* Then it is created as a root record category
*/
@Test
(
description = "Create root category"
)
public void createCategoryTest() throws Exception
{
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric();
// Build the record category properties
JsonObject recordCategoryProperties = buildObject().
add(NAME, categoryName).
add(NODE_TYPE, RECORD_CATEGORY_TYPE.toString()).
addObject(PROPERTIES).
add(PROPERTIES_TITLE, categoryTitle).
end().
getJson();
// Create the record category
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
// Verify the status code
restWrapper.assertStatusCodeIs(CREATED);
// Verify the returned file plan component
assertTrue(filePlanComponent.isIsCategory());
assertFalse(filePlanComponent.isIsFile());
assertFalse(filePlanComponent.isIsRecordFolder());
assertEquals(filePlanComponent.getName(), categoryName);
assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE.toString());
assertFalse(filePlanComponent.isHasRetentionSchedule());
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
// Verify the returned file plan component properties
FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties();
assertEquals(filePlanComponentProperties.getTitle(), categoryTitle);
logger.info("Aspects: " + filePlanComponent.getAspectNames());
}
/**
* <pre>
* Given that a record category exists
* When I ask the API to update the details of the record category
* Then the details of the record category are updated
*/
@Test
(
description = "Rename root category"
)
public void renameCategory() throws Exception
{
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create record category first
String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric();
// Build the record category properties
JsonObject recordCategoryProperties = buildObject().
add(NAME, categoryName).
add(NODE_TYPE, RECORD_CATEGORY_TYPE.toString()).
addObject(PROPERTIES).
add(PROPERTIES_TITLE, categoryTitle).
end().
getJson();
// Create the record category
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
String newCategoryName = "Rename " + categoryName;
// Build the properties which will be updated
JsonObject updateRecordCategoryProperties = buildObject().
add(NAME, newCategoryName).
getJson();
// Update the record category
FilePlanComponent renamedFilePlanComponent = filePlanComponentAPI.updateFilePlanComponent(updateRecordCategoryProperties, filePlanComponent.getId());
// Verify the status code
restWrapper.assertStatusCodeIs(OK);
// Verify the returned file plan component
assertEquals(renamedFilePlanComponent.getName(), newCategoryName);
// Get actual FILE_PLAN_ALIAS id
FilePlanComponent parentComponent = filePlanComponentAPI.getFilePlanComponent(FILE_PLAN_ALIAS.toString());
// verify renamed component still has this parent
assertEquals(renamedFilePlanComponent.getParentId(), parentComponent.getId());
}
/**
* <pre>
* Given that a record category exists
* When I ask the API to delete the record category
* Then the record category and all its contents is deleted
*/
@Test
(
description = "Delete category"
)
public void deleteCategory() throws Exception
{
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create record category first
String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric();
// Build the record category properties
JsonObject recordCategoryProperties = buildObject().
add(NAME, categoryName).
add(NODE_TYPE, RECORD_CATEGORY_TYPE.toString()).
addObject(PROPERTIES).
add(PROPERTIES_TITLE, categoryTitle).
end().
getJson();
// Create the record category
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
// Delete the record category
filePlanComponentAPI.deleteFilePlanComponent(filePlanComponent.getId());
// Verify the status code
restWrapper.assertStatusCodeIs(NO_CONTENT);
// Deleted component should no longer be retrievable
filePlanComponentAPI.getFilePlanComponent(filePlanComponent.getId());
restWrapper.assertStatusCodeIs(NOT_FOUND);
}
/**
* <pre>
* Given that a record category exists
* When I ask the API to create a record category
* Then it is created within the record category
*/
@Test
(
description = "Create child category"
)
public void createSubcategory() throws Exception
{
// Create root level category
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), getRandomAlphanumeric());
assertNotNull(rootCategory.getId());
// Create subcategory as a child of rootCategory
FilePlanComponent childCategory = createCategory(rootCategory.getId(), getRandomAlphanumeric());
// Child category created?
assertNotNull(childCategory.getId());
// Verify child category
assertEquals(childCategory.getParentId(), rootCategory.getId());
assertTrue(childCategory.isIsCategory());
assertFalse(childCategory.isIsFile());
assertFalse(childCategory.isIsRecordFolder());
assertEquals(childCategory.getNodeType(), RECORD_CATEGORY_TYPE.toString());
}
/**
* <pre>
* Given that a record category exists
* And contains a number of record categories and record folders
* When I ask the APi to get me the children of the record category
* Then I am returned the contained record categories and record folders
* And their details
*/
@Test
(
description = "List children of a category"
)
public void listChildren() throws Exception
{
// Create root level category
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), getRandomAlphanumeric());
assertNotNull(rootCategory.getId());
// Add child categories/folders
ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>();
for (int i=0; i < NUMBER_OF_CHILDREN; i++)
{
// Create a child
FilePlanComponent child = createComponent(rootCategory.getId(),
getRandomAlphanumeric(),
// half of the children should be subcategories, the other subfolders
(i <= NUMBER_OF_CHILDREN / 2) ? RECORD_CATEGORY_TYPE : RECORD_FOLDER_TYPE);
assertNotNull(child.getId());
children.add(child);
}
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// List children from API
FilePlanComponentsCollection apiChildren = filePlanComponentAPI.listChildComponents(rootCategory.getId());
// Check status code
restWrapper.assertStatusCodeIs(OK);
logger.info("parent: " + rootCategory.getId());
// Check listed children against created list
apiChildren.getEntries().forEach(c ->
{
FilePlanComponent filePlanComponent = c.getFilePlanComponent();
assertNotNull(filePlanComponent.getId());
logger.info("Checking child " + filePlanComponent.getId());
try
{
// Find this child in created children list
FilePlanComponent createdComponent = children.stream()
.filter(child -> child.getId().equals(filePlanComponent.getId()))
.findFirst()
.get();
// Created by
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
// Is parent Id set correctly?
assertEquals(filePlanComponent.getParentId(), rootCategory.getId());
// Only categories or folders have been created
assertFalse(filePlanComponent.isIsFile());
// Boolean properties related to node type
// Only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created
if (filePlanComponent.getNodeType().equals(RECORD_CATEGORY_TYPE.toString()))
{
assertTrue(filePlanComponent.isIsCategory());
assertFalse(filePlanComponent.isIsRecordFolder());
}
else
{
assertTrue(filePlanComponent.isIsRecordFolder());
assertFalse(filePlanComponent.isIsCategory());
}
// Does returned object have the same contents as the created one?
assertEquals(createdComponent.getName(), filePlanComponent.getName());
assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType());
// Verify properties
// FIXME: Verify properties
}
catch (NoSuchElementException e)
{
fail("No child element for " + filePlanComponent.getId());
}
});
}
/**
* Helper method to create child category
*
* @param parentCategoryId The id of the parent category
* @param categoryName The name of the category
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
{
return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE);
}
/**
* Helper method to create generic child component
*
* @param parentComponentId The id of the parent file plan component
* @param componentName The name of the file plan component
* @param componentType The name of the file plan component
* @return The created file plan component
* @throws Exception
*/
private FilePlanComponent createComponent(String parentComponentId, String componentName, FilePlanComponentType componentType) throws Exception
{
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
JsonObject componentProperties = buildObject().
add(NAME, componentName).
add(NODE_TYPE, componentType.toString()).
addObject(PROPERTIES).
add(PROPERTIES_TITLE, "Title for " + componentName).
end().
getJson();
FilePlanComponent fpc = filePlanComponentAPI.createFilePlanComponent(componentProperties, parentComponentId);
restWrapper.assertStatusCodeIs(CREATED);
return fpc;
}
}

View File

@@ -0,0 +1,368 @@
/*
* #%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.rm.fileplancomponents;
import static org.alfresco.rest.rm.base.TestData.CATEGORY_NAME;
import static org.alfresco.rest.rm.base.TestData.FOLDER_NAME;
import static org.alfresco.rest.rm.base.TestData.FOLDER_TITLE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.IS_CLOSED;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NAME;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_LOCATION;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_REVIEW_PERIOD;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
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.http.HttpStatus.UNPROCESSABLE_ENTITY;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail;
import static org.testng.AssertJUnit.assertTrue;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import com.google.gson.JsonObject;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.base.BaseRestTest;
import org.alfresco.rest.rm.base.TestData;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.rm.requests.FilePlanComponentAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.report.Bug;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
/**
* This class contains the tests for the
* the Record Folder CRUD API
*
* @author Rodica Sutu
* @since 2.6
*/
public class RecordFolderTests extends BaseRestTest
{
@Autowired
public FilePlanComponentAPI filePlanComponentAPI;
@Autowired
public DataUser dataUser;
private static final int NUMBER_OF_FOLDERS= 5;
/**
* Given that a record category exists
* When I use the API to create a new record folder
* Then it is created within the record category
*/
@Test
(
description = "Create a folder into a record category"
)
public void createFolderTest() throws Exception
{
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent filePlanComponent=createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
// Build the record category properties
JsonObject recordFolderProperties = buildObject()
.add(NAME, FOLDER_NAME)
.add(NODE_TYPE, RECORD_FOLDER_TYPE.toString())
.addObject(PROPERTIES)
.add(PROPERTIES_TITLE, FOLDER_TITLE)
.end()
.getJson();
// Create the record folder
FilePlanComponent folder = filePlanComponentAPI.createFilePlanComponent(recordFolderProperties, filePlanComponent.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
// Check folder has been created within the category created
assertEquals(filePlanComponent.getId(),folder.getParentId());
// Verify the returned properties for the file plan component - record folder
assertFalse(folder.isIsCategory());
assertFalse(folder.isIsFile());
assertTrue(folder.isIsRecordFolder());
assertEquals(folder.getName(), FOLDER_NAME);
assertEquals(folder.getNodeType(), RECORD_FOLDER_TYPE.toString());
assertEquals(folder.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
// Verify the returned file plan component properties
FilePlanComponentProperties folderProperties = folder.getProperties();
assertEquals(folderProperties.getTitle(), FOLDER_TITLE);
}
/**
* Given that RM site is created
* When I use the API to create a new record folder into transfers container/holds container/unfiled
* Then the operation fails
*/
@Test
(
description = "Create a folder into hold/transfers/unfiled/file plan container",
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
@Bug(id="RM-4327")
public void createFolderIntoSpecialContainers(String filePlanComponent) throws Exception
{
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String componentID = filePlanComponentAPI.getFilePlanComponent(filePlanComponent).getId();
// Build the record category properties
JsonObject recordFolderProperties = buildObject()
.add(NAME, FOLDER_NAME)
.add(NODE_TYPE, RECORD_FOLDER_TYPE.toString())
.addObject(PROPERTIES)
.add(PROPERTIES_TITLE, FOLDER_TITLE)
.end()
.getJson();
// Create a record folder
filePlanComponentAPI.createFilePlanComponent(recordFolderProperties, componentID);
// Check the API Response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
/**
* Given that a record folder exists
* When I ask for the details of a record folder
* Then I am given the details of a record folder
*/
@Test
(
description = "Check the details returned for a record folder"
)
public void checkTheRecordFolderProperties() throws Exception
{
String CATEGORY=CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
FilePlanComponent folder =createFolder(category.getId(),FOLDER_NAME);
FilePlanComponent folderDetails=filePlanComponentAPI.withParams("include="+IS_CLOSED).getFilePlanComponent(folder.getId());
// Verify the returned properties for the file plan component - record folder
assertEquals(RECORD_FOLDER_TYPE.toString(),folderDetails.getNodeType());
assertTrue(folderDetails.isIsRecordFolder());
assertFalse(folderDetails.isIsCategory());
assertFalse(folderDetails.isIsFile());
assertFalse(folderDetails.isClosed());
assertEquals(FOLDER_NAME,folderDetails.getName());
assertEquals(dataUser.getAdminUser().getUsername(),folderDetails.getCreatedByUser().getId());
assertEquals(dataUser.getAdminUser().getUsername(), folderDetails.getModifiedByUser().getId());
assertEquals(FOLDER_TITLE,folderDetails.getProperties().getTitle());
}
/**
* Given that a record folder exists
* When I use the API to update its details
* Then the details of the record folder are updated
* The above test does treat any custom metadata
* Note: the details of the record folder includes any custom meta-data
*/
@Test
(
description = "Update the details returned for a record folder"
)
public void updateTheRecordFolderProperties() throws Exception
{
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME);
// Create record category first
String folderDescription = "The folder description is updated" + getRandomAlphanumeric();
String folderName= "The folder name is updated" + getRandomAlphanumeric();
String folderTitle = "Update title " + getRandomAlphanumeric();
String location="Location"+getRandomAlphanumeric();
String review_period="month|1";
// Build the file plan root properties
JsonObject folderProperties = buildObject()
.add(NAME, folderName)
.addObject(PROPERTIES)
.add(PROPERTIES_TITLE, folderTitle)
.add(PROPERTIES_DESCRIPTION, folderDescription)
.add(PROPERTIES_VITAL_RECORD_INDICATOR,true)
.add(PROPERTIES_REVIEW_PERIOD, review_period)
.add(PROPERTIES_LOCATION, location)
.end()
.getJson();
// Update the record category
FilePlanComponent folderUpdated = filePlanComponentAPI.updateFilePlanComponent(folderProperties, folder.getId());
// Check the Response Status Code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK);
// Verify the returned properties for the file plan component - record folder
assertEquals(folderName, folderUpdated.getName());
assertEquals(folderDescription, folderUpdated.getProperties().getDescription());
assertEquals(folderTitle, folderUpdated.getProperties().getTitle());
assertTrue(folderUpdated.getProperties().isVitalRecord());
assertEquals(location, folderUpdated.getProperties().getLocation());
assertNotNull(folderUpdated.getProperties().getReviewPeriod().getPeriodType());
assertNotNull(folderUpdated.getProperties().getReviewPeriod().getExpression());
}
/**
* Given that a record folder exists
* When I use the API to delete the record folder
* Then it deleted according to the normal rules governing the deletion of record folders
*/
@Test
(
description = "Delete record folder"
)
public void deleteRecordFolder() throws Exception
{
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME);
// Delete the Record folder
filePlanComponentAPI.deleteFilePlanComponent(folder.getId());
// Check the Response Status Code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NO_CONTENT);
// Check the File Plan Component is not found
filePlanComponentAPI.getFilePlanComponent(folder.getId());
// Check the Response Status Code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND);
}
/**
* Given that a record category exists
* And contains several record folders
* When I use the APi to get the file plan component children for the existing category
* Then I am provided with a list of the contained record folders
* And their details
*/
@Test
(
description = "List children of a category"
)
public void listFolders() throws Exception
{
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
// Add child olders
ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>();
for (int i = 0; i < NUMBER_OF_FOLDERS; i++)
{
// Create a child
FilePlanComponent child = createFolder(category.getId(),
getRandomAlphanumeric());
assertNotNull(child.getId());
children.add(child);
}
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// List children from API
FilePlanComponentsCollection apiChildren = filePlanComponentAPI.listChildComponents(category.getId());
// Check status code
restWrapper.assertStatusCodeIs(OK);
// Check listed children against created list
apiChildren.getEntries().forEach(c ->
{
FilePlanComponent filePlanComponent = c.getFilePlanComponent();
assertNotNull(filePlanComponent.getId());
logger.info("Checking child " + filePlanComponent.getId());
try
{
// Find this child in created children list
FilePlanComponent createdComponent = children.stream()
.filter(child -> child.getId().equals(filePlanComponent.getId()))
.findFirst()
.get();
// Created by
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
// Is parent Id set correctly
assertEquals(filePlanComponent.getParentId(), category.getId());
assertFalse(filePlanComponent.isIsFile());
// Boolean properties related to node type
assertTrue(filePlanComponent.isIsRecordFolder());
assertFalse(filePlanComponent.isIsCategory());
assertEquals(createdComponent.getName(), filePlanComponent.getName());
assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType());
}
catch (NoSuchElementException e)
{
fail("No child element for " + filePlanComponent.getId());
}
}
);
}
@AfterClass (alwaysRun = true)
public void tearDown() throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
filePlanComponentAPI.listChildComponents(FILE_PLAN_ALIAS.toString()).getEntries().forEach(filePlanComponentEntry ->
{
try
{
filePlanComponentAPI.deleteFilePlanComponent(filePlanComponentEntry.getFilePlanComponent().getId());
}
catch (Exception e)
{
e.printStackTrace();
}
});
}
}

View File

@@ -0,0 +1,346 @@
/*
* #%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.rm.site;
import static org.alfresco.rest.rm.base.TestData.ANOTHER_ADMIN;
import static org.alfresco.rest.rm.base.TestData.DEFAULT_EMAIL;
import static org.alfresco.rest.rm.base.TestData.DEFAULT_PASSWORD;
import static org.alfresco.rest.rm.model.site.RMSiteCompliance.DOD5015;
import static org.alfresco.rest.rm.model.site.RMSiteCompliance.STANDARD;
import static org.alfresco.rest.rm.model.site.RMSiteFields.COMPLIANCE;
import static org.alfresco.rest.rm.model.site.RMSiteFields.DESCRIPTION;
import static org.alfresco.rest.rm.model.site.RMSiteFields.TITLE;
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.CONFLICT;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.FORBIDDEN;
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 static org.testng.Assert.assertNotNull;
import com.google.gson.JsonObject;
import org.alfresco.dataprep.UserService;
import org.alfresco.rest.rm.base.BaseRestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.model.site.RMSite;
import org.alfresco.rest.rm.requests.RMSiteAPI;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.RandomData;
import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.report.Bug;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.Test;
/**
* This class contains the tests for
* the RM site CRUD API
*
* @author Rodica Sutu
* @since 2.6
*/
public class RMSiteTests extends BaseRestTest
{
@Autowired
private UserService userService;
@Autowired
private RMSiteAPI rmSiteAPI;
@Autowired
private DataUser dataUser;
/**
* Given that RM module is installed
* When I want to create the RM site with specific title, description and compliance
* Then the RM site is created
*/
@Test
(
description = "Create RM site with Standard Compliance as admin user"
)
public void createRMSiteAsAdminUser() throws Exception
{
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Check if the RM site exists
if (siteRMExists())
{
// 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);
assertEquals(rmSite.getRole(), UserRole.SiteManager.toString());
}
/**
* Given that RM site exists
* When I want to create the RM site
* Then the response code 409 (Site with the given identifier already exists) is return
*/
@Test
(
description = "Create RM site when site already exist with admin user"
)
public void createRMSiteWhenSiteExists() throws Exception
{
// Create the RM site if it does not exist
createRMSiteIfNotExists();
// Authenticate with admin user
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);
}
/**
* Given that RM site exists
* When I want to delete the RM site
* Then RM site is successfully deleted
*/
@Test
(
description = "Delete RM site as admin user"
)
public void deleteRMSite() throws Exception
{
// Authenticate with admin user
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Delete the RM site
rmSiteAPI.deleteRMSite();
// Verify the status code
restWrapper.assertStatusCodeIs(NO_CONTENT);
}
/**
* Given that RM site exists
* When I GET the retrieve the RM site details
* Then RM site details are returned
*/
@Test
(
description = "GET the RM site as admin user"
)
public void getRMSite() throws Exception
{
// Authenticate with admin user
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Get the RM site
RMSite rmSite = rmSiteAPI.getSite();
if (!siteRMExists())
{
// Verify the status code when RM site doesn't exist
restWrapper.assertStatusCodeIs(NOT_FOUND);
createRMSiteIfNotExists();
}
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);
}
}
/**
* Given that an user is created and RM site doesn't exist
* When the user wants to create a RM site with DOD compliance
* Then RM site is created
*/
@Test
(
description = "Create RM site with DOD compliance as an another admin user"
)
@Bug (id="RM-4289")
public void createRMSiteAsAnotherAdminUser() throws Exception
{
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Check if the RM site exists
if (siteRMExists())
{
// Delete the RM site
rmSiteAPI.deleteRMSite();
}
// Disconnect the current user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
// Create user
userService.create(dataUser.getAdminUser().getUsername(),
dataUser.getAdminUser().getPassword(),
ANOTHER_ADMIN,
DEFAULT_PASSWORD,
DEFAULT_EMAIL,
ANOTHER_ADMIN,
ANOTHER_ADMIN);
// Build the user model
UserModel userModel = new UserModel(ANOTHER_ADMIN,DEFAULT_PASSWORD);
// Authenticate as that new user
rmSiteAPI.usingRestWrapper().authenticateUser(userModel);
// Build the RM site properties
JsonObject rmSiteProperties = buildObject()
.add(TITLE, RM_TITLE)
.add(DESCRIPTION, RM_DESCRIPTION)
.add(COMPLIANCE, DOD5015.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(), DOD5015);
assertEquals(rmSite.getVisibility(), PUBLIC);
assertEquals(rmSite.getRole(), UserRole.SiteManager.toString());
}
/**
* Given that RM site exist
* When a non-RM user wants to update the RM site details (title or description)
* Then 403 response status code is return
* When the admin user wants to update the RM site details (title or description)
* Then RM site details are updated
*/
@Test
public void updateRMSiteDetails()throws Exception
{
String NEW_TITLE = RM_TITLE + RandomData.getRandomAlphanumeric();
String NEW_DESCRIPTION=RM_DESCRIPTION+ RandomData.getRandomAlphanumeric();
// Build the RM site properties
JsonObject rmSiteToUpdate = buildObject()
.add(TITLE, NEW_TITLE)
.add(DESCRIPTION, NEW_DESCRIPTION)
.getJson();
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create the site if it does not exist
createRMSiteIfNotExists();
// Disconnect the user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
// Create a random user
UserModel nonRMuser = dataUser.createRandomTestUser("testUser");
// Authenticate as that random user
rmSiteAPI.usingRestWrapper().authenticateUser(nonRMuser);
// Create the RM site
RMSite rmSite = rmSiteAPI.updateRMSite(rmSiteToUpdate);
// Verify the status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
// Disconnect the user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Update the RM Site
rmSite = rmSiteAPI.updateRMSite(rmSiteToUpdate);
// Verify the response status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(OK);
// Verify the returned file plan component
assertEquals(rmSite.getId(), RM_ID);
assertEquals(rmSite.getTitle(), NEW_TITLE);
assertEquals(rmSite.getDescription(), NEW_DESCRIPTION);
assertNotNull(rmSite.getCompliance());
assertEquals(rmSite.getVisibility(), PUBLIC);
}
/**
* Given that RM site exist
* When the admin user wants to update the RM site compliance
* Then RM site compliance is not updated
*/
@Test
public void updateRMSiteComplianceAsAdmin() throws Exception
{
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create the RM site if it does not exist
createRMSiteIfNotExists();
// Build the RM site properties
JsonObject rmSiteToUpdate = buildObject()
.add(COMPLIANCE, DOD5015.toString())
.getJson();
// Update the RM site
rmSiteAPI.updateRMSite(rmSiteToUpdate);
// Verify the response status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST);
}
}

View File

@@ -0,0 +1,25 @@
#########################################################################
# Original property values from default.properties #
#########################################################################
# Dataprep related
alfresco.scheme=http
alfresco.server=localhost
alfresco.port=8080
# Credentials
admin.user=admin
admin.password=admin
# Rest related
rest.basePath=alfresco/api/-default-/public/alfresco/versions/1
rest.workflowPath=alfresco/api/-default-/public/workflow/versions/1
# Database Section
db.url = jdbc:mysql://${alfresco.server}:3306/alfresco
db.username = alfresco
db.password = alfresco
#########################################################################
rest.rmPath=alfresco/api/-default-/public/ig/versions/1

View File

@@ -0,0 +1,10 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestNG AllTestSuite" verbose="1" time-out="300000">
<test name="restapi">
<packages>
<package name="org.alfresco.rest.rm.*"/>
</packages>
</test>
</suite>

View File

@@ -36,7 +36,12 @@ rm.action.records_only_undeclared=You can only complete records.
rm.action.event-not-undone=You can't undo the event {0} because it's not defined on the retention lifecycle.
rm.action.node-not-record-category=You can't create a retention schedule for ({0}) because it's not a record category.
rm.action.parameter-not-supplied=Add a ''{0}'' to continue.
rm.action.delete-not-hold-type=We couldn't delete the hold because {1} isn't of type {0}.
rm.action.delete-not-hold-type=We couldn't delete the hold because {1} isn't of type {0}.
rm.action.cast-to-rm-type=You can't upload a custom folder type to the records management file plan.
rm.action.record-folder-create=You can't create a record folder in another record folder.
rm.action.unique.child.type-error-message=Operation failed. Multiple children of this type are not allowed.
rm.action.multiple.children.type-error-message=Operation failed. Children of type {0} are not allowed
rm.action.create.transfer.container.child-error-message=Operation failed. Creation is not allowed in Transfer Container.
rm.action.create.transfer.child-error-message=Operation failed. Creation is not allowed in Transfer Folders.
rm.action.create.record.folder.child-error-message=Only records can be created in record folders but it was {0}

View File

@@ -27,7 +27,6 @@
<property name="quickShareLinks" ref="rm.QuickShareLinks"/>
<property name="filePlanService" ref="FilePlanService"/>
<property name="recordsManagementServiceRegistry" ref="RecordsManagementServiceRegistry"/>
<property name="capabilityService" ref="CapabilityService"/>
</bean>
<bean id="rm.Nodes" class="org.springframework.aop.framework.ProxyFactoryBean">

View File

@@ -27,19 +27,20 @@
package org.alfresco.module.org_alfresco_module_rm.model;
import java.security.InvalidParameterException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.repo.policy.annotation.BehaviourRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.I18NUtil;
import com.google.common.collect.Sets;
@@ -56,6 +57,10 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl
/** Logger */
protected static final Log LOGGER = LogFactory.getLog(BaseBehaviourBean.class);
/** I18N */
protected static final String UNIQUE_CHILD_TYPE_ERROR = "rm.action.unique.child.type-error-message";
protected static final String MULTIPLE_CHILDREN_TYPE_ERROR = "rm.action.multiple.children.type-error-message";
/** behaviour filter */
protected BehaviourFilter behaviourFilter;
@@ -99,9 +104,9 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl
* @param childType the child node
* @param acceptedUniqueChildType a list of node types that are accepted as children of the provided parent only once
* @param acceptedMultipleChildType a list of node types that are accepted as children of the provided parent multiple times
* @throws InvalidParameterException if the child association doesn't comply with the RM rules
* @throws IntegrityException if the child association doesn't comply with the RM rules
*/
protected void validateNewChildAssociation(NodeRef parent, NodeRef child, List<QName> acceptedUniqueChildType, List<QName> acceptedMultipleChildType) throws InvalidParameterException
protected void validateNewChildAssociation(NodeRef parent, NodeRef child, List<QName> acceptedUniqueChildType, List<QName> acceptedMultipleChildType) throws IntegrityException
{
QName childType = getInternalNodeService().getType(child);
if(acceptedUniqueChildType.contains(childType))
@@ -109,12 +114,12 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl
// check the user is not trying to create multiple children of a type that is only accepted once
if(nodeService.getChildAssocs(parent, Sets.newHashSet(childType)).size() > 1)
{
throw new InvalidParameterException("Operation failed. Multiple children of this type are not allowed.");
throw new IntegrityException(I18NUtil.getMessage(UNIQUE_CHILD_TYPE_ERROR), null);
}
}
else if(!acceptedMultipleChildType.contains(childType))
{
throw new InvalidParameterException("Operation failed. Children of type " + childType + " are not allowed");
throw new IntegrityException(I18NUtil.getMessage(MULTIPLE_CHILDREN_TYPE_ERROR, childType), null);
}
}
@@ -122,9 +127,9 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl
* Helper method that checks if the newly created child association is between the sub-types of accepted types.
* @param childType the child node
* @param acceptedMultipleChildType a list of node types that are accepted as children of the provided parent multiple times
* @throws InvalidParameterException if the child association isn't between the sub-types of accepted types
* @throws IntegrityException if the child association isn't between the sub-types of accepted types
*/
protected void validateNewChildAssociationSubTypesIncluded(NodeRef child, List<QName> acceptedMultipleChildType) throws InvalidParameterException
protected void validateNewChildAssociationSubTypesIncluded(NodeRef child, List<QName> acceptedMultipleChildType) throws IntegrityException
{
QName childType = getInternalNodeService().getType(child);
for(QName type : acceptedMultipleChildType)
@@ -135,6 +140,6 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl
}
}
//no match was found in sub-types of permitted types list
throw new InvalidParameterException("Operation failed. Children of type " + childType + " are not allowed");
throw new IntegrityException(I18NUtil.getMessage(MULTIPLE_CHILDREN_TYPE_ERROR, childType), null);
}
}

View File

@@ -519,48 +519,45 @@ public class RecordsManagementSearchBehaviour implements RecordsManagementModel
*/
private void updateDispositionActionProperties(NodeRef record, NodeRef dispositionAction)
{
if (!methodCached("updateDispositionActionProperties", record))
Map<QName, Serializable> props = nodeService.getProperties(record);
DispositionAction da = new DispositionActionImpl(recordsManagementServiceRegistry, dispositionAction);
props.put(PROP_RS_DISPOSITION_ACTION_NAME, da.getName());
props.put(PROP_RS_DISPOSITION_ACTION_AS_OF, da.getAsOfDate());
props.put(PROP_RS_DISPOSITION_EVENTS_ELIGIBLE, nodeService.getProperty(dispositionAction, PROP_DISPOSITION_EVENTS_ELIGIBLE));
DispositionActionDefinition daDefinition = da.getDispositionActionDefinition();
if (daDefinition != null)
{
Map<QName, Serializable> props = nodeService.getProperties(record);
DispositionAction da = new DispositionActionImpl(recordsManagementServiceRegistry, dispositionAction);
props.put(PROP_RS_DISPOSITION_ACTION_NAME, da.getName());
props.put(PROP_RS_DISPOSITION_ACTION_AS_OF, da.getAsOfDate());
props.put(PROP_RS_DISPOSITION_EVENTS_ELIGIBLE, nodeService.getProperty(dispositionAction, PROP_DISPOSITION_EVENTS_ELIGIBLE));
DispositionActionDefinition daDefinition = da.getDispositionActionDefinition();
if (daDefinition != null)
Period period = daDefinition.getPeriod();
if (period != null)
{
Period period = daDefinition.getPeriod();
if (period != null)
{
props.put(PROP_RS_DISPOSITION_PERIOD, period.getPeriodType());
props.put(PROP_RS_DISPOSITION_PERIOD_EXPRESSION, period.getExpression());
}
else
{
props.put(PROP_RS_DISPOSITION_PERIOD, null);
props.put(PROP_RS_DISPOSITION_PERIOD_EXPRESSION, null);
}
props.put(PROP_RS_DISPOSITION_PERIOD, period.getPeriodType());
props.put(PROP_RS_DISPOSITION_PERIOD_EXPRESSION, period.getExpression());
}
nodeService.setProperties(record, props);
if (logger.isDebugEnabled())
else
{
logger.debug("Set rma:recordSearchDispositionActionName for node " + record + " to: " +
props.get(PROP_RS_DISPOSITION_ACTION_NAME));
logger.debug("Set rma:recordSearchDispositionActionAsOf for node " + record + " to: " +
props.get(PROP_RS_DISPOSITION_ACTION_AS_OF));
logger.debug("Set rma:recordSearchDispositionEventsEligible for node " + record + " to: " +
props.get(PROP_RS_DISPOSITION_EVENTS_ELIGIBLE));
logger.debug("Set rma:recordSearchDispositionPeriod for node " + record + " to: " +
props.get(PROP_RS_DISPOSITION_PERIOD));
logger.debug("Set rma:recordSearchDispositionPeriodExpression for node " + record + " to: " +
props.get(PROP_RS_DISPOSITION_PERIOD_EXPRESSION));
props.put(PROP_RS_DISPOSITION_PERIOD, null);
props.put(PROP_RS_DISPOSITION_PERIOD_EXPRESSION, null);
}
}
nodeService.setProperties(record, props);
if (logger.isDebugEnabled())
{
logger.debug("Set rma:recordSearchDispositionActionName for node " + record + " to: " +
props.get(PROP_RS_DISPOSITION_ACTION_NAME));
logger.debug("Set rma:recordSearchDispositionActionAsOf for node " + record + " to: " +
props.get(PROP_RS_DISPOSITION_ACTION_AS_OF));
logger.debug("Set rma:recordSearchDispositionEventsEligible for node " + record + " to: " +
props.get(PROP_RS_DISPOSITION_EVENTS_ELIGIBLE));
logger.debug("Set rma:recordSearchDispositionPeriod for node " + record + " to: " +
props.get(PROP_RS_DISPOSITION_PERIOD));
logger.debug("Set rma:recordSearchDispositionPeriodExpression for node " + record + " to: " +
props.get(PROP_RS_DISPOSITION_PERIOD_EXPRESSION));
}
}
/**

View File

@@ -27,8 +27,10 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
import org.alfresco.module.org_alfresco_module_rm.security.FilePlanPermissionService;
@@ -61,6 +63,9 @@ public class RecordCategoryType extends BaseBehaviourBean
implements NodeServicePolicies.OnCreateChildAssociationPolicy,
NodeServicePolicies.OnCreateNodePolicy
{
private final static List<QName> ACCEPTED_UNIQUE_CHILD_TYPES = new ArrayList<QName>();
private final static List<QName> ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_RECORD_CATEGORY, TYPE_RECORD_FOLDER);
/** vital record service */
protected VitalRecordService vitalRecordService;
@@ -106,13 +111,9 @@ public class RecordCategoryType extends BaseBehaviourBean
)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew)
{
// ensure content is not placed directly into a record category
NodeRef nodeRef = childAssocRef.getChildRef();
if (instanceOf(nodeRef, ContentModel.TYPE_CONTENT))
{
throw new AlfrescoRuntimeException("Operation failed, because you can't place content directly into a record category.");
}
NodeRef parentRef = childAssocRef.getParentRef();
validateNewChildAssociation(parentRef, nodeRef, ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES);
if (bNew)
{
// setup the record folder

View File

@@ -32,6 +32,7 @@ import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.model.behaviour.AbstractDisposableItem;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
@@ -40,6 +41,7 @@ import org.alfresco.repo.copy.CopyBehaviourCallback;
import org.alfresco.repo.copy.CopyDetails;
import org.alfresco.repo.copy.DefaultCopyBehaviourCallback;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.annotation.Behaviour;
import org.alfresco.repo.policy.annotation.BehaviourBean;
@@ -76,7 +78,7 @@ public class RecordFolderType extends AbstractDisposableItem
protected VitalRecordService vitalRecordService;
/** I18N */
private static final String MSG_CANNOT_CREATE_RECORD_FOLDER = "rm.action.record-folder-create";
private static final String MSG_CANNOT_CREATE_RECORD_FOLDER_CHILD = "rm.action.create.record.folder.child-error-message";
/**
* @param recordService record service
@@ -219,6 +221,15 @@ public class RecordFolderType extends AbstractDisposableItem
if (nodeService.exists(nodeRef))
{
boolean notFolderOrRmFolderSubType = !instanceOf(nodeRef, ContentModel.TYPE_FOLDER) ||
instanceOf(nodeRef, RecordsManagementModel.TYPE_RECORDS_MANAGEMENT_CONTAINER) ||
instanceOf(nodeRef, RecordsManagementModel.TYPE_RECORD_FOLDER) ||
instanceOf(nodeRef, RecordsManagementModel.TYPE_TRANSFER);
if (!instanceOf(nodeRef, ContentModel.TYPE_CONTENT) && notFolderOrRmFolderSubType)
{
throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_CREATE_RECORD_FOLDER_CHILD, nodeService.getType(nodeRef)), null);
}
// ensure nothing is being added to a closed record folder
NodeRef recordFolder = childAssocRef.getParentRef();
Boolean isClosed = (Boolean) nodeService.getProperty(recordFolder, PROP_IS_CLOSED);
@@ -245,9 +256,9 @@ public class RecordFolderType extends AbstractDisposableItem
final NodeRef recordFolder = childAssocRef.getChildRef();
// only records can be added in a record folder or hidden folders(is the case of e-mail attachments)
if (!instanceOf(recordFolder, ContentModel.TYPE_CONTENT) && !nodeService.hasAspect(recordFolder, ContentModel.ASPECT_HIDDEN))
if (instanceOf(recordFolder, ContentModel.TYPE_FOLDER) && !nodeService.hasAspect(recordFolder, ContentModel.ASPECT_HIDDEN))
{
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CANNOT_CREATE_RECORD_FOLDER));
throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_CREATE_RECORD_FOLDER_CHILD, nodeService.getType(recordFolder)), null);
}
behaviourFilter.disableBehaviour();

View File

@@ -28,7 +28,6 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import java.io.Serializable;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -41,6 +40,7 @@ import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchService;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.annotation.Behaviour;
import org.alfresco.repo.policy.annotation.BehaviourBean;
@@ -59,6 +59,7 @@ import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ParameterCheck;
import org.alfresco.util.PropertyMap;
import org.springframework.extensions.surf.util.I18NUtil;
import com.google.common.collect.Sets;
@@ -343,14 +344,14 @@ public class RmSiteType extends BaseBehaviourBean
*/
@Override
protected void validateNewChildAssociation(NodeRef parent, NodeRef child, List<QName> acceptedUniqueChildType,
List<QName> acceptedMultipleChildType) throws InvalidParameterException
List<QName> acceptedMultipleChildType) throws IntegrityException
{
super.validateNewChildAssociation(parent, child, acceptedUniqueChildType, acceptedMultipleChildType);
// check the user is not trying to create more than 2 folders that are created by default.
if(nodeService.getChildAssocs(parent, Sets.newHashSet(ContentModel.TYPE_FOLDER)).size() > 2)
{
throw new InvalidParameterException("Operation failed. Children of type " + ContentModel.TYPE_FOLDER + " are not allowed");
throw new IntegrityException(I18NUtil.getMessage(MULTIPLE_CHILDREN_TYPE_ERROR, ContentModel.TYPE_FOLDER), null);
}
}
}

View File

@@ -26,12 +26,11 @@
*/
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import java.security.InvalidParameterException;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.policy.annotation.Behaviour;
import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind;
@@ -50,6 +49,7 @@ public class TransferContainerType extends BaseBehaviourBean
implements NodeServicePolicies.OnCreateChildAssociationPolicy, NodeServicePolicies.OnCreateNodePolicy
{
private final static String MSG_ERROR_ADD_CONTENT_CONTAINER = "rm.service.error-add-content-container";
private final static String MSG_ERROR_ADD_CHILD_TO_TRANSFER_CONTAINER = "rm.action.create.transfer.container.child-error-message";
private static final String BEHAVIOUR_NAME = "onCreateChildAssocsForTransferContainer";
/**
@@ -84,7 +84,7 @@ public class TransferContainerType extends BaseBehaviourBean
)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew)
{
throw new InvalidParameterException("Operation failed. Creation is not allowed in Transfer Container");
throw new IntegrityException(I18NUtil.getMessage(MSG_ERROR_ADD_CHILD_TO_TRANSFER_CONTAINER), null);
}
@Override

View File

@@ -27,14 +27,14 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import java.security.InvalidParameterException;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.policy.annotation.Behaviour;
import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* rma:transfer behaviour bean
@@ -45,6 +45,7 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
@BehaviourBean(defaultType = "rma:transfer")
public class TransferType extends BaseBehaviourBean implements NodeServicePolicies.OnCreateChildAssociationPolicy
{
private final static String MSG_ERROR_ADD_CHILD_TO_TRANSFER = "rm.action.create.transfer.child-error-message";
private static final String BEHAVIOUR_NAME = "onCreateChildAssocsForTransferType";
/**
@@ -76,6 +77,6 @@ public class TransferType extends BaseBehaviourBean implements NodeServicePolici
)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
{
throw new InvalidParameterException("Operation failed. Creation is not allowed in Transfer Folders");
throw new IntegrityException(I18NUtil.getMessage(MSG_ERROR_ADD_CHILD_TO_TRANSFER), null);
}
}

View File

@@ -37,7 +37,6 @@ import java.util.concurrent.ConcurrentHashMap;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementServiceRegistry;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
@@ -65,8 +64,6 @@ import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck;
import net.sf.acegisecurity.vote.AccessDecisionVoter;
/**
* Centralizes access to the repository.
*
@@ -87,7 +84,6 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
private Repository repositoryHelper;
private DictionaryService dictionaryService;
private DispositionService dispositionService;
private CapabilityService capabilityService;
/**
* TODO to remove this after isSpecialNode is made protected in core implementation(REPO-1459)
@@ -117,11 +113,6 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
this.filePlanService = filePlanService;
}
public void setCapabilityService(CapabilityService capabilityService)
{
this.capabilityService = capabilityService;
}
@Override
public Node getFolderOrDocument(final NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, List<String> includeParam, Map<String, UserInfo> mapUserInfo)
{
@@ -132,6 +123,26 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
nodeTypeQName = nodeService.getType(nodeRef);
}
//TODO to remove this part of code after isSpecialNode will be made protected on core, will not need this anymore since the right allowed operations will be returned from core(REPO-1459).
if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS) && originalNode.getAllowableOperations() != null)
{
List<String> allowableOperations = originalNode.getAllowableOperations();
List<String> modifiedAllowableOperations = new ArrayList<>();
modifiedAllowableOperations.addAll(allowableOperations);
for (String op : allowableOperations)
{
if (op.equals(OP_DELETE) && (isSpecialNode(nodeRef, nodeTypeQName)))
{
// special case: do not return "delete" (as an allowable op) for specific system nodes
modifiedAllowableOperations.remove(op);
}
}
originalNode.setAllowableOperations((modifiedAllowableOperations.size() > 0 )? modifiedAllowableOperations : null);
}
RMNodeType type = getType(nodeTypeQName, nodeRef);
FileplanComponentNode node = null;
if (mapUserInfo == null)
@@ -182,55 +193,9 @@ public class RMNodesImpl extends NodesImpl implements RMNodes
}
}
if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS))
{
node.setAllowableOperations(getAllowableOperations(nodeRef, type));
}
return node;
}
/**
* Helper method that generates allowable operation for the provided node
* @param nodeRef the node to get the allowable operations for
* @param type the type of the provided nodeRef
* @return a sublist of [{@link Nodes.OP_DELETE}, {@link Nodes.OP_CREATE}, {@link Nodes.OP_UPDATE}] representing the allowable operations for the provided node
*/
private List<String> getAllowableOperations(NodeRef nodeRef, RMNodeType type)
{
List<String> allowableOperations = new ArrayList<>();
NodeRef filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
boolean isFilePlan = nodeRef.equals(filePlan);
boolean isTransferContainer = nodeRef.equals(filePlanService.getTransferContainer(filePlan));
boolean isUnfiledContainer = nodeRef.equals(filePlanService.getUnfiledContainer(filePlan));
boolean isHoldsContainer = nodeRef.equals(filePlanService.getHoldContainer(filePlan)) ;
boolean isSpecialContainer = isFilePlan || isTransferContainer || isUnfiledContainer || isHoldsContainer;
// DELETE
if(!isSpecialContainer &&
capabilityService.getCapability("Delete").evaluate(nodeRef) == AccessDecisionVoter.ACCESS_GRANTED)
{
allowableOperations.add(OP_DELETE);
}
// CREATE
if(type != RMNodeType.FILE &&
!isTransferContainer &&
capabilityService.getCapability("FillingPermissionOnly").evaluate(nodeRef) == AccessDecisionVoter.ACCESS_GRANTED)
{
allowableOperations.add(OP_CREATE);
}
// UPDATE
if (capabilityService.getCapability("Update").evaluate(nodeRef) == AccessDecisionVoter.ACCESS_GRANTED)
{
allowableOperations.add(OP_UPDATE);
}
return allowableOperations;
}
@Override
public NodeRef validateNode(String nodeId)
{

View File

@@ -46,7 +46,7 @@ import org.alfresco.rm.rest.api.model.SiteUpdate;
* @since 2.6
*
*/
@EntityResource(name = "sites", title = "IG Sites")
@EntityResource(name = "ig-sites", title = "IG Sites")
public class RMSiteEntityResource implements EntityResourceAction.Delete, EntityResourceAction.Create<RMSite>,
EntityResourceAction.Update<RMSite>, EntityResourceAction.ReadById<RMSite>
{

View File

@@ -66,6 +66,10 @@ public class MultipleSchedulesTest extends BaseRMTestCase
protected static final String CATEGORY_B_NAME = TEST_PREFIX + "CategoryB";
/** The name to use for the folder within the second category. */
protected static final String FOLDER_B_NAME = TEST_PREFIX + "FolderB";
/** The name to use for the third category. */
protected static final String CATEGORY_C_NAME = TEST_PREFIX + "CategoryC";
/** The name to use for the folder within the third category. */
protected static final String FOLDER_C_NAME = TEST_PREFIX + "FolderC";
/** The name to use for the record. */
protected static final String RECORD_NAME = TEST_PREFIX + "Record";
@@ -80,6 +84,10 @@ public class MultipleSchedulesTest extends BaseRMTestCase
private NodeRef categoryB;
/** The folder node within the second category. */
private NodeRef folderB;
/** The third category node. */
private NodeRef categoryC;
/** The folder node within the third category. */
private NodeRef folderC;
/** The record node. */
private NodeRef record;
@@ -114,6 +122,7 @@ public class MultipleSchedulesTest extends BaseRMTestCase
// Create two categories.
categoryA = filePlanService.createRecordCategory(filePlan, CATEGORY_A_NAME);
categoryB = filePlanService.createRecordCategory(filePlan, CATEGORY_B_NAME);
categoryC = filePlanService.createRecordCategory(filePlan, CATEGORY_C_NAME);
// Create a disposition schedule for category A (Cut off immediately, then Destroy immediately).
DispositionSchedule dispSchedA = utils.createBasicDispositionSchedule(categoryA, "instructions", "authority", true, false);
Map<QName, Serializable> cutOffParamsA = ImmutableMap.of(PROP_DISPOSITION_ACTION_NAME, CutOffAction.NAME,
@@ -135,9 +144,21 @@ public class MultipleSchedulesTest extends BaseRMTestCase
PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_ONE_WEEK,
PROP_DISPOSITION_PERIOD_PROPERTY, PROP_CUT_OFF_DATE);
dispositionService.addDispositionActionDefinition(dispSchedB, destroyParamsB);
// Create a disposition schedule for category C (Cut off immediately, then Destroy one year after cutoff).
DispositionSchedule dispSchedC = utils.createBasicDispositionSchedule(categoryC, "instructions", "authority", true, false);
Map<QName, Serializable> cutOffParamsC = ImmutableMap.of(PROP_DISPOSITION_ACTION_NAME, CutOffAction.NAME,
PROP_DISPOSITION_DESCRIPTION, "description",
PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_IMMEDIATELY);
dispositionService.addDispositionActionDefinition(dispSchedC, cutOffParamsC);
Map<QName, Serializable> destroyParamsC = ImmutableMap.of(PROP_DISPOSITION_ACTION_NAME, DestroyAction.NAME,
PROP_DISPOSITION_DESCRIPTION, "description",
PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_ONE_YEAR,
PROP_DISPOSITION_PERIOD_PROPERTY, PROP_CUT_OFF_DATE);
dispositionService.addDispositionActionDefinition(dispSchedC, destroyParamsC);
// Create a folder within each category.
folderA = recordFolderService.createRecordFolder(categoryA, FOLDER_A_NAME);
folderB = recordFolderService.createRecordFolder(categoryB, FOLDER_B_NAME);
folderC = recordFolderService.createRecordFolder(categoryC, FOLDER_C_NAME);
}
/**
@@ -155,6 +176,7 @@ public class MultipleSchedulesTest extends BaseRMTestCase
test()
.given(() -> {
setUpFilePlan();
// Create a record filed under category A and linked to category B.
record = fileFolderService.create(folderA, RECORD_NAME, ContentModel.TYPE_CONTENT).getNodeRef();
recordService.link(record, folderB);
@@ -219,19 +241,22 @@ public class MultipleSchedulesTest extends BaseRMTestCase
test()
.given(() -> {
setUpFilePlan();
// Create a record filed under category A and linked to category B.
// Create a record filed under category A and linked to category B and C.
record = fileFolderService.create(folderA, RECORD_NAME, ContentModel.TYPE_CONTENT).getNodeRef();
recordService.link(record, folderB);
})
.when(() -> {
recordService.link(record, folderC);
// Cut off the record.
dispositionService.cutoffDisposableItem(record);
// Ensure the update has been applied to the record.
internalDispositionService.updateNextDispositionAction(record);
})
.when(() -> {
// Unlink the record from folder B.
recordService.unlink(record, folderB);
})
.then()
.expect(true)
.expect(false)
.from(() -> dispositionService.isNextDispositionActionEligible(record))
.because("Destroy action should be available, as the record should follow its origin disposition schedule.");
.because("Destroy action shouldn't be available, as the record should follow disposition schedule from category C.");
}
}

View File

@@ -27,11 +27,10 @@
*/
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
import java.security.InvalidParameterException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AccessStatus;
@@ -78,7 +77,7 @@ public class RM3341Test extends BaseRMTestCase
fileFolderService.create(holdContainer, "test file", ContentModel.TYPE_CONTENT);
fail("This should have thrown an exception");
}
catch (InvalidParameterException e)
catch (IntegrityException e)
{
// ("Content can't be added to a hold container. Use record folders to file content.")
}
@@ -104,7 +103,7 @@ public class RM3341Test extends BaseRMTestCase
fail("This should have thrown an exception");
}
catch (InvalidParameterException e)
catch (IntegrityException e)
{
// ("Content can't be added to a transfer container. Use record folders to file content.")
}

View File

@@ -26,10 +26,9 @@
*/
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
import java.security.InvalidParameterException;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.module.org_alfresco_module_rm.test.util.TestModel;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.util.GUID;
import org.springframework.extensions.surf.util.I18NUtil;
@@ -50,7 +49,7 @@ public class RM3450Test extends BaseRMTestCase
doTestInTransaction(new FailureTest
(
I18NUtil.getMessage(MSG_CANNOT_CAST_TO_RM_TYPE),
InvalidParameterException.class
IntegrityException.class
)
{
@Override

View File

@@ -29,11 +29,11 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.when;
import java.security.InvalidParameterException;
import java.util.Arrays;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
@@ -69,7 +69,7 @@ public class FilePlanTypeUnitTest extends BaseUnitTest
* When adding a child of type TYPE_FILE_PLAN
* Then an error should be thrown
*/
@Test (expected = InvalidParameterException.class)
@Test (expected = IntegrityException.class)
public void testAddFileplanToFileplan()
{
ChildAssociationRef childAssoc = createFileplanContainerChild(TYPE_FILE_PLAN);
@@ -112,7 +112,7 @@ public class FilePlanTypeUnitTest extends BaseUnitTest
* When adding another child of type TYPE_HOLD_CONTAINER
* Then an error should be thrown
*/
@Test (expected = InvalidParameterException.class)
@Test (expected = IntegrityException.class)
public void testCreateMultipleHoldContainers()
{
ChildAssociationRef existingHoldAssoc = createFileplanContainerChild(TYPE_HOLD_CONTAINER);
@@ -141,7 +141,7 @@ public class FilePlanTypeUnitTest extends BaseUnitTest
* When adding another child of type TYPE_TRANSFER_CONTAINER
* Then an error should be thrown
*/
@Test (expected = InvalidParameterException.class)
@Test (expected = IntegrityException.class)
public void testCreateMultipleTransferContainers()
{
ChildAssociationRef existingHoldAssoc = createFileplanContainerChild(TYPE_TRANSFER_CONTAINER);
@@ -170,7 +170,7 @@ public class FilePlanTypeUnitTest extends BaseUnitTest
* When adding another child of type TYPE_UNFILED_RECORD_CONTAINER
* Then an error should be thrown
*/
@Test (expected = InvalidParameterException.class)
@Test (expected = IntegrityException.class)
public void testCreateMultipleUnfiledRecordsContainers()
{
ChildAssociationRef existingHoldAssoc = createFileplanContainerChild(TYPE_UNFILED_RECORD_CONTAINER);

View File

@@ -29,10 +29,9 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.security.InvalidParameterException;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
@@ -52,9 +51,9 @@ public class HoldContainerTypeUnitTest extends BaseUnitTest
/**
* Given that we try to add a non "rma:hold" type to hold container,
* Then InvalidParameterException is thrown.
* Then IntegrityException is thrown.
*/
@Test (expected = InvalidParameterException.class)
@Test (expected = IntegrityException.class)
public void testAddNonHoldTypeToHoldContainer()
{
QName type = AlfMock.generateQName();

View File

@@ -0,0 +1,111 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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/>.
* #L%
*/
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.when;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper;
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordService;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* Unit test class for RecordCategoryType
*
* @author Silviu Dinuta
* @since 2.6
*
*/
public class RecordCategoryTypeUnitTest extends BaseUnitTest
{
@Mock
private AuthenticationUtil mockAuthenticationUtil;
@Mock
private VitalRecordService mockedVitalRecordService;
private @InjectMocks RecordCategoryType recordCategoryType;
@Before
public void setup()
{
MockitoAnnotations.initMocks(this);
MockAuthenticationUtilHelper.setup(mockAuthenticationUtil);
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
}
/**
* Given that we try to add types different than "rma:recordCategory" and "rma:recordFolder" to a record category,
* Then IntegrityException is thrown.
*/
@Test(expected = IntegrityException.class)
public void testCreateNonAceptedTypes() throws Exception
{
NodeRef recordCategoryNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_CATEGORY);
QName type = AlfMock.generateQName();
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordCategoryNodeRef, nodeRef);
recordCategoryType.onCreateChildAssociation(childAssocRef, true);
}
/**
* Given that we try to add "rma:recordCategory" type to a record category,
* Then operation is successful.
*/
@Test
public void testCreateRecordCategory() throws Exception
{
NodeRef recordCategoryNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_CATEGORY);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_CATEGORY, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordCategoryNodeRef, nodeRef);
recordCategoryType.onCreateChildAssociation(childAssocRef, true);
}
/**
* Given that we try to add "rma:recordFolder" type to a record category,
* Then operation is successful.
*/
@Test
public void testCreateRecordFolder() throws Exception
{
NodeRef recordCategoryNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_CATEGORY);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordCategoryNodeRef, nodeRef);
recordCategoryType.onCreateChildAssociation(childAssocRef, true);
}
}

View File

@@ -0,0 +1,226 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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/>.
* #L%
*/
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.when;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper;
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordService;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* Unit test class for RecordFolderType
*
* @author Silviu Dinuta
* @since 2.6
*
*/
public class RecordFolderTypeUnitTest extends BaseUnitTest
{
@Mock
private AuthenticationUtil mockAuthenticationUtil;
@Mock
private VitalRecordService mockedVitalRecordService;
private @InjectMocks RecordFolderType recordFolderType;
@Before
public void setup()
{
MockitoAnnotations.initMocks(this);
MockAuthenticationUtilHelper.setup(mockAuthenticationUtil);
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
}
/**
* Given that we try to add one rma:transfer to a record folder,
* Then IntegrityException is thrown.
*/
@Test(expected = IntegrityException.class)
public void testCreateTransferFolder() throws Exception
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_TRANSFER)).thenReturn(true);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
}
/**
* Given that we try to add one record folder to a record folder,
* Then IntegrityException is thrown.
*/
@Test(expected = IntegrityException.class)
public void testCreateRecordFolder() throws Exception
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_RECORD_FOLDER)).thenReturn(true);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
}
/**
* Given that we try to add sub-type of rma:recordsManagementContainer to a record folder,
* Then IntegrityException is thrown.
*/
@Test(expected = IntegrityException.class)
public void testCreateSubTypesOfRecordManagementContainer() throws Exception
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_RECORDS_MANAGEMENT_CONTAINER)).thenReturn(true);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
}
/**
* Given that we try to add cm:folder sub-type to a record folder,
* Then the operation is successful.
*/
@Test
public void testCreateFolderSubType() throws Exception
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_FOLDER)).thenReturn(true);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
}
/**
* Given that we try to add non cm:folder sub-type to a record folder,
* Then IntegrityException is thrown.
*/
@Test(expected = IntegrityException.class)
public void testCreateNonFolderSubType() throws Exception
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_FOLDER)).thenReturn(false);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
}
/**
* Given that we try to add cm:content sub-type to a record folder,
* Then the operation is successful.
*/
public void testCreateContent() throws Exception
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_CONTENT)).thenReturn(true);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
}
/**
* Given that we try to add non cm:content or non cm:folder sub-type to a record folder,
* Then IntegrityException is thrown.
*/
@Test(expected = IntegrityException.class)
public void testCreateNonContent() throws Exception
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_CONTENT)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, TYPE_FOLDER)).thenReturn(false);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
}
/**
* Given that we try to add not hidden cm:folder sub-type to a record folder,
* Then IntegrityException is thrown on commit.
*/
@Test(expected = IntegrityException.class)
public void testCreateNotHiddenFolderSubTypeOnCommit() throws Exception
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_FOLDER)).thenReturn(true);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociationOnCommit(childAssocRef, true);
}
/**
* Given that we try to add hidden cm:folder sub-type to a record folder,
* Then the operation is successful.
*/
@Test
public void testCreateHiddenFolderSubTypeOnCommit() throws Exception
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
when(mockedDictionaryService.isSubClass(type, TYPE_FOLDER)).thenReturn(true);
when(mockedNodeService.hasAspect(nodeRef, ASPECT_HIDDEN)).thenReturn(true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociationOnCommit(childAssocRef, true);
}
/**
* Given that we try to add non cm:folder sub-type to a record folder,
* Then the operation is successful.
*/
@Test
public void testCreateNonFolderSubTypeOnCommit() throws Exception
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
when(mockedDictionaryService.isSubClass(type, TYPE_FOLDER)).thenReturn(false);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociationOnCommit(childAssocRef, true);
}
}

View File

@@ -30,7 +30,6 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import org.alfresco.module.org_alfresco_module_rm.dod5015.DOD5015Model;
@@ -38,6 +37,7 @@ import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper;
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.site.SiteInfo;
@@ -77,9 +77,9 @@ public class RmSiteTypeUnitTest extends BaseUnitTest implements DOD5015Model
/**
* Given that we try to add non allowed type to rm site,
* Then InvalidParameterException is thrown.
* Then IntegrityException is thrown.
*/
@Test(expected = InvalidParameterException.class)
@Test(expected = IntegrityException.class)
public void testAddNonAcceptedTypeToRmSite()
{
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_RM_SITE, true);
@@ -149,9 +149,9 @@ public class RmSiteTypeUnitTest extends BaseUnitTest implements DOD5015Model
/**
* Given that we try to add more than two cm:folder to rm site,
* Then InvalidParameterException is thrown.
* Then IntegrityException is thrown.
*/
@Test(expected = InvalidParameterException.class)
@Test(expected = IntegrityException.class)
public void testAddMoreThanTwhoFolderTypeToRmSite()
{
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_RM_SITE, true);
@@ -208,9 +208,9 @@ public class RmSiteTypeUnitTest extends BaseUnitTest implements DOD5015Model
/**
* Given that we try to add one dod:filePlan to standard rm site,
* Then InvalidParameterException is thrown.
* Then IntegrityException is thrown.
*/
@Test(expected = InvalidParameterException.class)
@Test(expected = IntegrityException.class)
public void testAddDODFilePlanTypeToStandardRmSite()
{
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_RM_SITE, true);
@@ -225,9 +225,9 @@ public class RmSiteTypeUnitTest extends BaseUnitTest implements DOD5015Model
/**
* Given that we try to add more than one rma:filePlan to rm site,
* Then InvalidParameterException is thrown.
* Then IntegrityException is thrown.
*/
@Test(expected = InvalidParameterException.class)
@Test(expected = IntegrityException.class)
public void testAddMoreThanOneFilePlanTypeToRmSite()
{
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_RM_SITE, true);
@@ -281,9 +281,9 @@ public class RmSiteTypeUnitTest extends BaseUnitTest implements DOD5015Model
/**
* Given that we try to add more than one dod:filePlan to rm site,
* Then InvalidParameterException is thrown.
* Then IntegrityException is thrown.
*/
@Test(expected = InvalidParameterException.class)
@Test(expected = IntegrityException.class)
public void testAddMoreThanOneDODFilePlanTypeToRmSite()
{
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_DOD_5015_SITE, true);
@@ -315,9 +315,9 @@ public class RmSiteTypeUnitTest extends BaseUnitTest implements DOD5015Model
/**
* Given that we try to add one rma:filePlan to DOD rm site,
* Then InvalidParameterException is thrown.
* Then IntegrityException is thrown.
*/
@Test(expected = InvalidParameterException.class)
@Test(expected = IntegrityException.class)
public void testAddStandardFilePlanTypeToDODRmSite()
{
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_DOD_5015_SITE, true);

View File

@@ -29,10 +29,9 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.security.InvalidParameterException;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
@@ -52,9 +51,9 @@ public class TransferContainerTypeUnitTest extends BaseUnitTest
/**
* Given that we try to add to transfer container,
* Then InvalidParameterException is thrown.
* Then IntegrityException is thrown.
*/
@Test(expected = InvalidParameterException.class)
@Test(expected = IntegrityException.class)
public void testAddToTransferContainerTest()
{
NodeRef transferContainer = generateNodeRef(TYPE_TRANSFER_CONTAINER, true);

View File

@@ -30,10 +30,9 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.security.InvalidParameterException;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
@@ -53,9 +52,9 @@ public class TransferTypeUnitTest extends BaseUnitTest
/**
* Given that we try to add to transfer type folder,
* Then InvalidParameterException is thrown.
* Then IntegrityException is thrown.
*/
@Test(expected = InvalidParameterException.class)
@Test(expected = IntegrityException.class)
public void testAddToTransferFolderTest()
{
NodeRef transferFolder = generateNodeRef(TYPE_TRANSFER, true);

View File

@@ -30,11 +30,10 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.security.InvalidParameterException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
@@ -54,9 +53,9 @@ public class UnfiledRecordContainerTypeUnitTest extends BaseUnitTest
/**
* Given that we try to add a type that is not one of "rma:unfiledRecordFolder", "cm:content" or "rma:nonElectronicDocument" types to unfiled record container,
* Then InvalidParameterException is thrown.
* Then IntegrityException is thrown.
*/
@Test(expected = InvalidParameterException.class)
@Test(expected = IntegrityException.class)
public void testAddNonAcceptedTypeToUnfiledRecordContainer()
{
QName type = AlfMock.generateQName();

View File

@@ -30,11 +30,10 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.security.InvalidParameterException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
@@ -54,9 +53,9 @@ public class UnfiledRecordFolderTypeUnitTest extends BaseUnitTest
/**
* Given that we try to add a type that is not one of "rma:unfiledRecordFolder", "cm:content" or "rma:nonElectronicDocument" types to unfiled record folder,
* Then InvalidParameterException is thrown.
* Then IntegrityException is thrown.
*/
@Test(expected = InvalidParameterException.class)
@Test(expected = IntegrityException.class)
public void testAddNonAcceptedTypeToUnfiledRecordFolder()
{
QName type = AlfMock.generateQName();

View File

@@ -30,6 +30,7 @@ package org.alfresco.rm.rest.api.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
@@ -44,8 +45,6 @@ import java.util.ArrayList;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
@@ -75,8 +74,6 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import net.sf.acegisecurity.vote.AccessDecisionVoter;
/**
* Unit Test class for RMNodesImpl.
*
@@ -106,17 +103,10 @@ public class RMNodesImplUnitTest extends BaseUnitTest
@Mock
private ServiceRegistry mockedServiceRegistry;
@Mock
private CapabilityService mockedCapabilityService;
@InjectMocks
private RMNodesImpl rmNodesImpl;
private Capability deleteCapability;
private Capability createCapability;
private Capability updateCapability;
@Before
public void before()
{
@@ -127,12 +117,6 @@ public class RMNodesImplUnitTest extends BaseUnitTest
when(mockedNamespaceService.getPrefixes(any(String.class))).thenReturn(prefixes);
when(mockedNamespaceService.getNamespaceURI(any(String.class))).thenReturn(RM_URI);
deleteCapability = mock(Capability.class);
when(mockedCapabilityService.getCapability("Delete")).thenReturn(deleteCapability);
createCapability = mock(Capability.class);
when(mockedCapabilityService.getCapability("FillingPermissionOnly")).thenReturn(createCapability);
updateCapability = mock(Capability.class);
when(mockedCapabilityService.getCapability("Update")).thenReturn(updateCapability);
}
@Test
@@ -176,13 +160,19 @@ public class RMNodesImplUnitTest extends BaseUnitTest
setPermissions(nodeRef, AccessStatus.ALLOWED);
when(deleteCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(createCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(updateCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(mockedFilePlanService.getFilePlanBySiteId(RM_SITE_ID)).thenReturn(nodeRef);
Node folderOrDocument = rmNodesImpl.getFolderOrDocument(nodeRef, null, null, includeParamList, null);
checksAllowedOperations(folderOrDocument, false, true, false);
assertNotNull(folderOrDocument);
assertTrue(FileplanComponentNode.class.isInstance(folderOrDocument));
FileplanComponentNode resultNode = (FileplanComponentNode) folderOrDocument;
assertEquals(false, resultNode.getIsRecordFolder());
assertEquals(false, resultNode.getIsFile());
assertEquals(false, resultNode.getIsCategory());
List<String> allowableOperations = resultNode.getAllowableOperations();
assertTrue("Create operation should be available for FilePlan.", allowableOperations.contains(RMNodes.OP_CREATE));
assertTrue("Update operation should be available for FilePlan.", allowableOperations.contains(RMNodes.OP_UPDATE));
assertFalse("Delete operation should note be available for FilePlan.", allowableOperations.contains(RMNodes.OP_DELETE));
}
@Test
@@ -213,15 +203,15 @@ public class RMNodesImplUnitTest extends BaseUnitTest
assertEquals(false, resultNode.getIsFile());
assertEquals(false, resultNode.getIsCategory());
List<String> allowableOperations = resultNode.getAllowableOperations();
assertEquals(0, allowableOperations.size());
assertNull(allowableOperations);
}
@Test
public void testGetTransferContainerAllowableOperations() throws Exception
{
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodeService.getType(nodeRef)).thenReturn(RecordsManagementModel.TYPE_TRANSFER_CONTAINER);
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_TRANSFER_CONTAINER, ContentModel.TYPE_FOLDER)).thenReturn(true);
when(mockedNodeService.getType(nodeRef)).thenReturn(RecordsManagementModel.TYPE_RECORD_CATEGORY);
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_RECORD_CATEGORY, ContentModel.TYPE_FOLDER)).thenReturn(true);
setupCompanyHomeAndPrimaryParent(nodeRef);
@@ -234,22 +224,16 @@ public class RMNodesImplUnitTest extends BaseUnitTest
when(mockedFilePlanService.getFilePlanBySiteId(RM_SITE_ID)).thenReturn(filePlanNodeRef);
when(mockedFilePlanService.getTransferContainer(filePlanNodeRef)).thenReturn(nodeRef);
when(deleteCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(createCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(updateCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(mockedFilePlanService.isFilePlanComponent(nodeRef)).thenReturn(true);
Node folderOrDocument = rmNodesImpl.getFolderOrDocument(nodeRef, null, null, includeParamList, null);
checksAllowedOperations(folderOrDocument, false, true, false);
checkSpecialContainersAllowedOperations(folderOrDocument);
}
@Test
public void testGetHoldContainerAllowableOperations() throws Exception
{
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodeService.getType(nodeRef)).thenReturn(RecordsManagementModel.TYPE_HOLD_CONTAINER);
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_HOLD_CONTAINER, ContentModel.TYPE_FOLDER)).thenReturn(true);
when(mockedNodeService.getType(nodeRef)).thenReturn(RecordsManagementModel.TYPE_RECORD_CATEGORY);
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_RECORD_CATEGORY, ContentModel.TYPE_FOLDER)).thenReturn(true);
setupCompanyHomeAndPrimaryParent(nodeRef);
@@ -266,22 +250,16 @@ public class RMNodesImplUnitTest extends BaseUnitTest
when(mockedFilePlanService.getHoldContainer(filePlanNodeRef)).thenReturn(nodeRef);
when(deleteCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(createCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(updateCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(mockedFilePlanService.isFilePlanComponent(nodeRef)).thenReturn(true);
Node folderOrDocument = rmNodesImpl.getFolderOrDocument(nodeRef, null, null, includeParamList, null);
checksAllowedOperations(folderOrDocument, true, true, false);
checkSpecialContainersAllowedOperations(folderOrDocument);
}
@Test
public void testGetUnfiledContainerAllowableOperations() throws Exception
{
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedNodeService.getType(nodeRef)).thenReturn(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER, ContentModel.TYPE_FOLDER)).thenReturn(true);
when(mockedNodeService.getType(nodeRef)).thenReturn(RecordsManagementModel.TYPE_RECORD_CATEGORY);
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_RECORD_CATEGORY, ContentModel.TYPE_FOLDER)).thenReturn(true);
setupCompanyHomeAndPrimaryParent(nodeRef);
@@ -301,14 +279,8 @@ public class RMNodesImplUnitTest extends BaseUnitTest
when(mockedFilePlanService.getUnfiledContainer(filePlanNodeRef)).thenReturn(nodeRef);
when(deleteCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(createCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(updateCapability.evaluate(nodeRef)).thenReturn(AccessDecisionVoter.ACCESS_GRANTED);
when(mockedFilePlanService.isFilePlanComponent(nodeRef)).thenReturn(true);
Node folderOrDocument = rmNodesImpl.getFolderOrDocument(nodeRef, null, null, includeParamList, null);
checksAllowedOperations(folderOrDocument, true, true, false);
checkSpecialContainersAllowedOperations(folderOrDocument);
}
@Test
@@ -769,23 +741,18 @@ public class RMNodesImplUnitTest extends BaseUnitTest
when(mockedPermissionService.hasPermission(nodeRef, PermissionService.ADD_CHILDREN)).thenReturn(permissionToSet);
}
private void checksAllowedOperations(Node containerNode, boolean allowCreate, boolean allowUpdate, boolean allowDelete)
private void checkSpecialContainersAllowedOperations(Node containerNode)
{
assertNotNull(containerNode);
assertTrue(FileplanComponentNode.class.isInstance(containerNode));
FileplanComponentNode resultNode = (FileplanComponentNode) containerNode;
assertTrue(RecordCategoryNode.class.isInstance(containerNode));
RecordCategoryNode resultNode = (RecordCategoryNode) containerNode;
assertEquals(false, resultNode.getIsRecordFolder());
assertEquals(false, resultNode.getIsFile());
assertEquals(true, resultNode.getIsCategory());
List<String> allowableOperations = resultNode.getAllowableOperations();
assertEquals("Create operation should " + (allowCreate?"":"not ") + "be available for provided container.",
allowCreate,
allowableOperations.contains(RMNodes.OP_CREATE));
assertEquals("Update operation should " + (allowCreate?"":"not ") + "be available for provided container.",
allowUpdate,
allowableOperations.contains(RMNodes.OP_UPDATE));
assertEquals("Delete operation should " + (allowCreate?"":"not ") + "be available for provided container.",
allowDelete,
allowableOperations.contains(RMNodes.OP_DELETE));
assertTrue("Create operation should be available for provided container.", allowableOperations.contains(RMNodes.OP_CREATE));
assertTrue("Update operation should be available for provided container.", allowableOperations.contains(RMNodes.OP_UPDATE));
assertFalse("Delete operation should note be available for provided container.", allowableOperations.contains(RMNodes.OP_DELETE));
}
}