Search in sources :

Example 1 with WebApiParam

use of org.alfresco.rest.framework.WebApiParam in project alfresco-remote-api by Alfresco.

the class ResourceInspector method inspectParameters.

/**
 * Inspects the Method to find any @WebApiParameters and @WebApiParam
 * @param resource the class
 * @param aMethod the method
 * @param httpMethod HttpMethod
 * @return a List of parameters
 */
private static List<ResourceParameter> inspectParameters(Class<?> resource, Method aMethod, HttpMethod httpMethod) {
    List<ResourceParameter> params = new ArrayList<ResourceParameter>();
    Annotation annot = AnnotationUtils.findAnnotation(aMethod, WebApiParameters.class);
    if (annot != null) {
        Map<String, Object> annotAttribs = AnnotationUtils.getAnnotationAttributes(annot);
        WebApiParam[] apiParams = (WebApiParam[]) annotAttribs.get("value");
        for (int i = 0; i < apiParams.length; i++) {
            params.add(findResourceParameter(apiParams[i], resource, aMethod));
        }
    } else {
        Annotation paramAnot = AnnotationUtils.findAnnotation(aMethod, WebApiParam.class);
        if (paramAnot != null) {
            params.add(findResourceParameter(paramAnot, resource, aMethod));
        }
    }
    // Setup default parameters
    switch(httpMethod) {
        case POST:
            if (paramsCount(params, ResourceParameter.KIND.URL_PATH) == 0) {
                params.add(ResourceParameter.ENTITY_PARAM);
            }
            if (paramsCount(params, ResourceParameter.KIND.HTTP_BODY_OBJECT) == 0) {
                inspectBodyParamAndReturnType(resource, aMethod, params);
            }
            break;
        case PUT:
            int urlPathForPut = paramsCount(params, ResourceParameter.KIND.URL_PATH);
            if (urlPathForPut == 0) {
                params.add(ResourceParameter.ENTITY_PARAM);
            }
            if (RelationshipResourceAction.Update.class.isAssignableFrom(resource) && urlPathForPut < 2) {
                params.add(ResourceParameter.RELATIONSHIP_PARAM);
            }
            if (paramsCount(params, ResourceParameter.KIND.HTTP_BODY_OBJECT) == 0) {
                inspectBodyParamAndReturnType(resource, aMethod, params);
            }
            break;
        case GET:
            int urlPathForGet = paramsCount(params, ResourceParameter.KIND.URL_PATH);
            if (urlPathForGet == 0 && (EntityResourceAction.ReadById.class.isAssignableFrom(resource) && READ_BY_ID_METHODNAME.equals(aMethod.getName()))) {
                params.add(ResourceParameter.ENTITY_PARAM);
            } else if (RelationshipResourceAction.ReadById.class.isAssignableFrom(resource) || RelationshipResourceAction.Read.class.isAssignableFrom(resource)) {
                // Its a RelationshipResourceAction
                if (urlPathForGet == 0) {
                    params.add(ResourceParameter.ENTITY_PARAM);
                }
                // This method is what we are inspecting not what the class implements.
                if (READ_BY_ID_METHODNAME.equals(aMethod.getName()) && urlPathForGet < 2) {
                    params.add(ResourceParameter.RELATIONSHIP_PARAM);
                }
            }
            if (!READ_BY_ID_METHODNAME.equals(aMethod.getName())) {
                params.add(ResourceParameter.SKIP_PARAM);
                params.add(ResourceParameter.MAX_ITEMS_PARAM);
                params.add(ResourceParameter.PROPS_PARAM);
            }
            break;
        case DELETE:
            int urlPathForDelete = paramsCount(params, ResourceParameter.KIND.URL_PATH);
            if (urlPathForDelete == 0) {
                params.add(ResourceParameter.ENTITY_PARAM);
            }
            // Add relationship param ?
            if (RelationshipResourceAction.Delete.class.isAssignableFrom(resource) && urlPathForDelete < 2) {
                params.add(ResourceParameter.RELATIONSHIP_PARAM);
            }
    }
    return params;
}
Also used : ArrayList(java.util.ArrayList) WebApiParam(org.alfresco.rest.framework.WebApiParam) Annotation(java.lang.annotation.Annotation) RelationshipResourceAction(org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction) MultiPartRelationshipResourceAction(org.alfresco.rest.framework.resource.actions.interfaces.MultiPartRelationshipResourceAction)

Example 2 with WebApiParam

use of org.alfresco.rest.framework.WebApiParam in project alfresco-remote-api by Alfresco.

the class PeopleEntityResource method create.

@Override
@WebApiDescription(title = "Create person", description = "Create a person")
@WebApiParam(name = "persons", title = "A single person", description = "A single person, multiple people are not supported.", kind = ResourceParameter.KIND.HTTP_BODY_OBJECT, allowMultiple = false, required = true)
public List<Person> create(List<Person> persons, Parameters parameters) {
    Person p = persons.get(0);
    validateDerivedFieldsExistence(p);
    List<Person> result = new ArrayList<>(1);
    result.add(people.create(p));
    return result;
}
Also used : ArrayList(java.util.ArrayList) Person(org.alfresco.rest.api.model.Person) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) WebApiParam(org.alfresco.rest.framework.WebApiParam)

Example 3 with WebApiParam

use of org.alfresco.rest.framework.WebApiParam in project records-management by Alfresco.

the class UnfiledContainerEntityResource method readById.

@WebApiDescription(title = "Get unfiled container information", description = "Gets information for a unfiled container with id 'unfiledContainerId'")
@WebApiParam(name = "unfiledContainerId", title = "The unfiled container id")
public UnfiledContainer readById(String unfiledContainerId, Parameters parameters) {
    checkNotBlank("unfiledContainerId", unfiledContainerId);
    mandatory("parameters", parameters);
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(unfiledContainerId, RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
    FileInfo info = fileFolderService.getFileInfo(nodeRef);
    return nodesModelFactory.createUnfiledContainer(info, parameters, null, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) WebApiParam(org.alfresco.rest.framework.WebApiParam)

Example 4 with WebApiParam

use of org.alfresco.rest.framework.WebApiParam in project records-management by Alfresco.

the class RecordFolderChildrenRelation method create.

@Override
@WebApiDescription(title = "Upload file content and meta-data into the repository.")
@WebApiParam(name = "formData", title = "A single form data", description = "A single form data which holds FormFields.")
public Record create(String recordFolderId, FormData formData, Parameters parameters, WithResponse withResponse) {
    checkNotBlank("recordFolderId", recordFolderId);
    mandatory("formData", formData);
    mandatory("parameters", parameters);
    // Retrieve the input data and resolve the parent node
    final UploadInfo uploadInfo = new UploadInfo(formData);
    final NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(recordFolderId, RecordsManagementModel.TYPE_RECORD_FOLDER, uploadInfo.getRelativePath());
    // Create the record
    RetryingTransactionCallback<NodeRef> callback = new RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() {
            return apiUtils.uploadRecord(parentNodeRef, uploadInfo, parameters);
        }
    };
    NodeRef newNode = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    // Get file info for response
    FileInfo info = fileFolderService.getFileInfo(newNode);
    apiUtils.postActivity(info, parentNodeRef, ActivityType.FILE_ADDED);
    return nodesModelFactory.createRecord(info, parameters, null, false);
}
Also used : UploadInfo(org.alfresco.rm.rest.api.model.UploadInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) WebApiParam(org.alfresco.rest.framework.WebApiParam)

Example 5 with WebApiParam

use of org.alfresco.rest.framework.WebApiParam in project records-management by Alfresco.

the class TransferContainerEntityResource method readById.

@WebApiDescription(title = "Get transfer container information", description = "Gets information for a transfer container with id 'transferContainerId'")
@WebApiParam(name = "transferContainerId", title = "The transfer container id")
@Override
public TransferContainer readById(String transferContainerId, Parameters parameters) throws EntityNotFoundException {
    checkNotBlank("transferContainerId", transferContainerId);
    mandatory("parameters", parameters);
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(transferContainerId, RecordsManagementModel.TYPE_TRANSFER_CONTAINER);
    FileInfo info = fileFolderService.getFileInfo(nodeRef);
    return nodesModelFactory.createTransferContainer(info, parameters, null, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) WebApiParam(org.alfresco.rest.framework.WebApiParam)

Aggregations

WebApiParam (org.alfresco.rest.framework.WebApiParam)14 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)13 FileInfo (org.alfresco.service.cmr.model.FileInfo)11 NodeRef (org.alfresco.service.cmr.repository.NodeRef)11 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)3 UploadInfo (org.alfresco.rm.rest.api.model.UploadInfo)3 ArrayList (java.util.ArrayList)2 Annotation (java.lang.annotation.Annotation)1 NodeRating (org.alfresco.rest.api.model.NodeRating)1 Person (org.alfresco.rest.api.model.Person)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 MultiPartRelationshipResourceAction (org.alfresco.rest.framework.resource.actions.interfaces.MultiPartRelationshipResourceAction)1 RelationshipResourceAction (org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction)1 QName (org.alfresco.service.namespace.QName)1 Pair (org.alfresco.util.Pair)1