use of org.alfresco.rest.framework.Operation in project records-management by Alfresco.
the class FilesEntityResource method declareAsRecord.
@Operation("declare")
@WebApiDescription(title = "Declare as record", description = "Declare a file as record.")
public Record declareAsRecord(String fileId, Void body, Parameters parameters, WithResponse withResponse) {
// Get fileplan
NodeRef filePlan = authenticationUtil.runAsSystem(new RunAsWork<NodeRef>() {
@Override
public NodeRef doWork() {
return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
}
});
// default false (if not provided)
boolean hideRecord = Boolean.valueOf(parameters.getParameter(Record.PARAM_HIDE_RECORD));
// Create the record
NodeRef file = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, fileId);
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {
public Void execute() {
recordService.createRecord(filePlan, file, !hideRecord);
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
// Return record state
FileInfo info = fileFolderService.getFileInfo(file);
return nodesModelFactory.createRecord(info, parameters, null, false);
}
use of org.alfresco.rest.framework.Operation in project records-management by Alfresco.
the class RecordsEntityResource method fileRecord.
@Operation("file")
@WebApiDescription(title = "File record", description = "File a record into fileplan.")
public Record fileRecord(String recordId, TargetContainer target, Parameters parameters, WithResponse withResponse) {
checkNotBlank("recordId", recordId);
mandatory("target", target);
mandatory("targetParentId", target.getTargetParentId());
mandatory("parameters", parameters);
// Get record and target folder
NodeRef record = apiUtils.validateRecord(recordId);
NodeRef targetRecordFolder = apiUtils.lookupAndValidateNodeType(target.getTargetParentId(), RecordsManagementModel.TYPE_RECORD_FOLDER);
// Get the current parent type to decide if we link or move the record
NodeRef primaryParent = nodeService.getPrimaryParent(record).getParentRef();
if (RecordsManagementModel.TYPE_RECORD_FOLDER.equals(nodeService.getType(primaryParent))) {
recordService.link(record, targetRecordFolder);
} else {
try {
fileFolderService.moveFrom(record, primaryParent, targetRecordFolder, null);
} catch (FileExistsException e) {
throw new IntegrityException(e.getMessage(), null);
} catch (FileNotFoundException e) {
throw new ConcurrencyFailureException("The record was deleted while filing it", e);
}
}
// return record state
FileInfo info = fileFolderService.getFileInfo(record);
return nodesModelFactory.createRecord(info, parameters, null, false);
}
use of org.alfresco.rest.framework.Operation in project records-management by Alfresco.
the class RecordsEntityResource method completeRecord.
@Operation("complete")
@WebApiDescription(title = "Complete record", description = "Complete a record.")
public Record completeRecord(String recordId, Void body, Parameters parameters, WithResponse withResponse) {
checkNotBlank("recordId", recordId);
mandatory("parameters", parameters);
// Get record
NodeRef record = apiUtils.validateRecord(recordId);
// Complete the record
try {
recordService.complete(record);
} catch (RecordMissingMetadataException e) {
throw new IntegrityException("The record has missing mandatory properties.", null);
}
// return record state
FileInfo info = fileFolderService.getFileInfo(record);
return nodesModelFactory.createRecord(info, parameters, null, false);
}
use of org.alfresco.rest.framework.Operation in project alfresco-remote-api by Alfresco.
the class NodeVersionsRelation method revertById.
@Operation("revert")
@WebApiDescription(title = "Revert Version", description = "Reverts (ie. promotes) specified version to become a new, most recent, version", successStatus = HttpServletResponse.SC_OK)
public Node revertById(String nodeId, String versionId, VersionOptions versionOptions, Parameters parameters, WithResponse withResponse) {
Version v = findVersion(nodeId, versionId);
if (v != null) {
CheckOutCheckInService cociService = sr.getCheckOutCheckInService();
NodeRef nodeRef = v.getVersionedNodeRef();
String versionComment = versionOptions.getComment();
VersionType versionType = VersionType.MINOR;
Boolean versionMajor = versionOptions.getMajorVersion();
if ((versionMajor != null) && (versionMajor)) {
versionType = VersionType.MAJOR;
}
Map<String, Serializable> versionProperties = new HashMap<>(2);
versionProperties.put(VersionModel.PROP_VERSION_TYPE, versionType);
if (versionComment != null) {
versionProperties.put(VersionModel.PROP_DESCRIPTION, versionComment);
}
// cancel editing if we want to revert
if (sr.getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY)) {
nodeRef = cociService.cancelCheckout(nodeRef);
}
// TODO review default for deep and/or whether we should make it an option
versionService.revert(nodeRef, v, false);
// Checkout/Checkin the node - to store the new version in version history
NodeRef wcNodeRef = cociService.checkout(nodeRef);
cociService.checkin(wcNodeRef, versionProperties);
// get latest version
v = versionService.getVersionHistory(nodeRef).getHeadVersion();
Node node = nodes.getFolderOrDocumentFullInfo(v.getFrozenStateNodeRef(), null, null, parameters, null);
mapVersionInfo(v, node);
return node;
}
throw new EntityNotFoundException(nodeId + "-" + versionId);
}
Aggregations