- Create a utility class with the toJson() method to convert models to json object

- update the test to use models
This commit is contained in:
Rodica Sutu
2016-11-28 10:11:01 +02:00
parent 74b8e0ac18
commit e87df92099
14 changed files with 283 additions and 293 deletions

View File

@@ -55,22 +55,22 @@ public class FilePlanComponent
private String nodeType;
@JsonProperty (required = true)
private boolean isCategory;
private Boolean isCategory;
@JsonProperty (required = true)
private boolean isRecordFolder;
private Boolean isRecordFolder;
@JsonProperty (required = true)
private boolean isFile;
private Boolean isFile;
@JsonProperty
private boolean hasRetentionSchedule;
private Boolean hasRetentionSchedule;
@JsonProperty(value = IS_CLOSED)
private boolean isClosed;
private Boolean isClosed;
@JsonProperty
private boolean isCompleted;
private Boolean isCompleted;
@JsonProperty (required = true)
private List<String> aspectNames;
@@ -88,13 +88,32 @@ public class FilePlanComponent
@JsonProperty (required = true)
private String modifiedAt;
@JsonProperty (required = true)
private String createdAt;
@JsonProperty (required = true)
private FilePlanComponentUserInfo modifiedByUser;
public FilePlanComponent(String name, String nodeType, FilePlanComponentProperties properties)
{
this.name = name;
this.nodeType = nodeType;
this.properties = properties;
}
public FilePlanComponent()
{
}
public FilePlanComponent(String name)
{
this.name = name;
}
public FilePlanComponent(String name, FilePlanComponentProperties properties)
{
this.name = name;
this.properties = properties;
}
/**
* @return the id
@@ -163,7 +182,7 @@ public class FilePlanComponent
/**
* @return the isCategory
*/
public boolean isIsCategory()
public Boolean isIsCategory()
{
return this.isCategory;
}
@@ -171,7 +190,7 @@ public class FilePlanComponent
/**
* @param isCategory the isCategory to set
*/
public void setCategory(boolean isCategory)
public void setCategory(Boolean isCategory)
{
this.isCategory = isCategory;
}
@@ -179,7 +198,7 @@ public class FilePlanComponent
/**
* @return the isRecordFolder
*/
public boolean isIsRecordFolder()
public Boolean isIsRecordFolder()
{
return this.isRecordFolder;
}
@@ -187,7 +206,7 @@ public class FilePlanComponent
/**
* @param isRecordFolder the isRecordFolder to set
*/
public void setRecordFolder(boolean isRecordFolder)
public void setRecordFolder(Boolean isRecordFolder)
{
this.isRecordFolder = isRecordFolder;
}
@@ -195,7 +214,7 @@ public class FilePlanComponent
/**
* @return the isFile
*/
public boolean isIsFile()
public Boolean isIsFile()
{
return this.isFile;
}
@@ -203,7 +222,7 @@ public class FilePlanComponent
/**
* @param isFile the isFile to set
*/
public void setFile(boolean isFile)
public void setFile(Boolean isFile)
{
this.isFile = isFile;
}
@@ -211,7 +230,7 @@ public class FilePlanComponent
/**
* @return the hasRetentionSchedule
*/
public boolean isHasRetentionSchedule()
public Boolean isHasRetentionSchedule()
{
return this.hasRetentionSchedule;
}
@@ -219,7 +238,7 @@ public class FilePlanComponent
/**
* @param hasRetentionSchedule the hasRetentionSchedule to set
*/
public void setHasRetentionSchedule(boolean hasRetentionSchedule)
public void setHasRetentionSchedule(Boolean hasRetentionSchedule)
{
this.hasRetentionSchedule = hasRetentionSchedule;
}
@@ -347,7 +366,7 @@ public class FilePlanComponent
/**
* @return the isClosed
*/
public boolean isClosed()
public Boolean isClosed()
{
return this.isClosed;
}
@@ -355,7 +374,7 @@ public class FilePlanComponent
/**
* @param closed the isClosed to set
*/
public void setClosed(boolean closed)
public void setClosed(Boolean closed)
{
this.isClosed = closed;
}
@@ -363,7 +382,7 @@ public class FilePlanComponent
/**
* @return the isCompleted
*/
public boolean isCompleted()
public Boolean isCompleted()
{
return this.isCompleted;
}
@@ -371,7 +390,7 @@ public class FilePlanComponent
/**
* @param completed the isCompleted to set
*/
public void setCompleted(boolean completed)
public void setCompleted(Boolean completed)
{
this.isCompleted = completed;
}

View File

@@ -40,7 +40,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
public class FilePlanComponentPath
{
private String name;
private boolean isComplete;
private Boolean isComplete;
private List<FilePlanComponentIdNamePair> elements;
/**
@@ -62,7 +62,7 @@ public class FilePlanComponentPath
/**
* @return the isComplete
*/
public boolean isComplete()
public Boolean isComplete()
{
return this.isComplete;
}
@@ -70,7 +70,7 @@ public class FilePlanComponentPath
/**
* @param isComplete the isComplete to set
*/
public void setComplete(boolean isComplete)
public void setComplete(Boolean isComplete)
{
this.isComplete = isComplete;
}

View File

@@ -38,6 +38,9 @@ import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.alfresco.rest.rm.community.util.ReviewPeriodSerializer;
/**
* POJO for file plan component properties
@@ -51,7 +54,7 @@ public class FilePlanComponentProperties
{
@JsonProperty(PROPERTIES_VITAL_RECORD_INDICATOR)
private boolean vitalRecord;
private Boolean vitalRecord;
@JsonProperty(PROPERTIES_TITLE)
private String title;
@@ -66,16 +69,32 @@ public class FilePlanComponentProperties
private List<String> supplementalMarkingList;
@JsonProperty(PROPERTIES_REVIEW_PERIOD)
@JsonSerialize (using = ReviewPeriodSerializer.class)
private ReviewPeriod reviewPeriod;
@JsonProperty(PROPERTIES_LOCATION)
private String location;
public FilePlanComponentProperties(String title, String description)
{
this.title = title;
this.description = description;
}
public FilePlanComponentProperties(String title)
{
this.title = title;
}
public FilePlanComponentProperties()
{
}
/**
* @return the vitalRecord
*/
public boolean isVitalRecord()
public Boolean isVitalRecord()
{
return this.vitalRecord;
}
@@ -83,7 +102,7 @@ public class FilePlanComponentProperties
/**
* @param vitalRecord the vitalRecord to set
*/
public void setVitalRecord(boolean vitalRecord)
public void setVitalRecord(Boolean vitalRecord)
{
this.vitalRecord = vitalRecord;
}
@@ -183,4 +202,5 @@ public class FilePlanComponentProperties
{
this.location = location;
}
}

View File

@@ -32,11 +32,22 @@ package org.alfresco.rest.rm.community.model.fileplancomponents;
* @author Rodica Sutu
* @since 2.6
*/
public class ReviewPeriod
{
private String periodType;
private String expression;
public ReviewPeriod(String periodType, String expression)
{
this.periodType = periodType;
this.expression = expression;
}
public ReviewPeriod()
{
}
/**
* @return the periodType
*/

View File

@@ -26,7 +26,10 @@
*/
package org.alfresco.rest.rm.community.model.site;
import static org.alfresco.rest.rm.community.model.site.RMSiteFields.COMPLIANCE;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.Gson;
import org.alfresco.rest.model.RestSiteModel;
@@ -38,9 +41,24 @@ import org.alfresco.rest.model.RestSiteModel;
*/
public class RMSite extends RestSiteModel
{
@JsonProperty (required = true)
@JsonProperty (value = COMPLIANCE,required = true)
private RMSiteCompliance compliance;
public RMSite(String title, String description, RMSiteCompliance compliance)
{
this.title=title;
this.description=description;
this.compliance=compliance;
}
public RMSite() { }
public RMSite(RMSiteCompliance compliance)
{
super();
this.compliance = compliance;
}
/**
* Helper method to set RM site compliance
*
@@ -60,4 +78,5 @@ public class RMSite extends RestSiteModel
{
return compliance;
}
}

View File

@@ -30,13 +30,12 @@ import static org.alfresco.rest.core.RestRequest.requestWithBody;
import static org.alfresco.rest.core.RestRequest.simpleRequest;
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryObject;
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryString;
import static org.alfresco.rest.rm.community.util.PojoUtility.toJson;
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.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
@@ -103,7 +102,7 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
/**
* 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 filePlanComponentModel 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:
@@ -116,14 +115,14 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
* <li>model integrity exception, including node name with invalid characters</li>
* </ul>
*/
public FilePlanComponent createFilePlanComponent(JsonObject filePlanComponentProperties, String parentId) throws Exception
public FilePlanComponent createFilePlanComponent(FilePlanComponent filePlanComponentModel, String parentId) throws Exception
{
mandatoryObject("filePlanComponentProperties", filePlanComponentProperties);
mandatoryObject("filePlanComponentProperties", filePlanComponentModel);
mandatoryString("parentId", parentId);
return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody(
POST,
filePlanComponentProperties.toString(),
toJson(filePlanComponentModel),
"fileplan-components/{fileplanComponentId}/children",
parentId
));
@@ -132,7 +131,7 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
/**
* Updates a file plan component
*
* @param filePlanComponentProperties The properties to be updated
* @param filePlanComponent 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:
@@ -145,14 +144,14 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
* <li>model integrity exception, including node name with invalid characters</li>
* </ul>
*/
public FilePlanComponent updateFilePlanComponent(JsonObject filePlanComponentProperties, String filePlanComponentId) throws Exception
public FilePlanComponent updateFilePlanComponent(FilePlanComponent filePlanComponent, String filePlanComponentId) throws Exception
{
mandatoryObject("filePlanComponentProperties", filePlanComponentProperties);
mandatoryObject("filePlanComponentProperties", filePlanComponent);
mandatoryString("filePlanComponentId", filePlanComponentId);
return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody(
PUT,
filePlanComponentProperties.toString(),
toJson(filePlanComponent),
"fileplan-components/{fileplanComponentId}",
filePlanComponentId
));
@@ -181,4 +180,5 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
filePlanComponentId
));
}
}

View File

@@ -29,14 +29,13 @@ package org.alfresco.rest.rm.community.requests;
import static org.alfresco.rest.core.RestRequest.requestWithBody;
import static org.alfresco.rest.core.RestRequest.simpleRequest;
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryObject;
import static org.alfresco.rest.rm.community.util.PojoUtility.toJson;
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 static org.springframework.http.HttpStatus.OK;
import com.google.gson.JsonObject;
import org.alfresco.rest.core.RestAPI;
import org.alfresco.rest.rm.community.model.site.RMSite;
import org.alfresco.utility.data.DataUser;
@@ -81,7 +80,7 @@ public class RMSiteAPI extends RestAPI<RMSiteAPI>
/**
* Create the RM site
*
* @param rmSiteProperties The properties of the rm site to be created
* @param rmSite The properties of the rm site to be created
* @return The {@link RMSite} with the given properties
* @throws Exception for the following cases:
* <ul>
@@ -91,13 +90,13 @@ public class RMSiteAPI extends RestAPI<RMSiteAPI>
* <li>Api Response code default Unexpected error</li>
* </ul>
*/
public RMSite createRMSite(JsonObject rmSiteProperties) throws Exception
public RMSite createRMSite(RMSite rmSite) throws Exception
{
mandatoryObject("rmSiteProperties", rmSiteProperties);
mandatoryObject("rmSiteProperties", rmSite);
return usingRestWrapper().processModel(RMSite.class, requestWithBody(
POST,
rmSiteProperties.toString(),
toJson(rmSite),
"ig-sites"
));
}
@@ -135,13 +134,13 @@ public class RMSiteAPI extends RestAPI<RMSiteAPI>
* <li>Api Response code default Unexpected error,model integrity exception</li>
* </ul>
*/
public RMSite updateRMSite(JsonObject rmSiteProperties) throws Exception
public RMSite updateRMSite(RMSite rmSiteProperties) throws Exception
{
mandatoryObject("rmSiteProperties", rmSiteProperties);
return usingRestWrapper().processModel(RMSite.class, requestWithBody(
PUT,
rmSiteProperties.toString(),
toJson(rmSiteProperties),
"ig-sites/rm"
));
}

View File

@@ -0,0 +1,66 @@
/*
* #%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.rest.rm.community.util;
import java.io.IOException;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Utility class for creating the json object
*
* @author Rodica Sutu
* @since 2.6
*/
public class PojoUtility
{
public static String toJson(Object rmModel) throws JsonProcessingException
{
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_DEFAULT);
try
{
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rmModel);
System.out.println("Json object generated is :" + json);
return json;
} catch (JsonGenerationException e)
{
return e.toString();
} catch (JsonMappingException e)
{
return e.toString();
} catch (IOException e)
{
return e.toString();
}
}
}