/* * #%L * Alfresco Records Management Module * %% * Copyright (C) 2005 - 2016 Alfresco Software Limited * %% * License rights for this program may be obtained from Alfresco Software, Ltd. * pursuant to a written agreement and any use of this program without such an * agreement is prohibited. * #L% */ package org.alfresco.rest.requests; import static org.alfresco.rest.core.RestRequest.requestWithBody; import static org.alfresco.rest.core.RestRequest.simpleRequest; import static org.alfresco.rest.util.ParameterCheck.mandatoryObject; import static org.alfresco.rest.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.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.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 1.0 */ @Component @Scope(value = "prototype") public class FilePlanComponentAPI extends RestAPI { /** * 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: * */ 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: * */ 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: * */ 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: * */ 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: * */ public void deleteFilePlanComponent(String filePlanComponentId) throws Exception { mandatoryString("filePlanComponentId", filePlanComponentId); usingRestWrapper().processEmptyModel(simpleRequest( DELETE, "fileplan-components/{fileplanComponentId}", filePlanComponentId )); } }