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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations