use of org.alfresco.service.cmr.model.FileInfo in project records-management by Alfresco.
the class UnfiledRecordFolderEntityResource method update.
@Override
@WebApiDescription(title = "Update unfiled record folder", description = "Updates an unfiled record folder with id 'unfiledRecordFolderId'")
public UnfiledRecordFolder update(String unfiledRecordFolderId, UnfiledRecordFolder unfiledRecordFolderInfo, Parameters parameters) {
checkNotBlank("unfiledRecordFolderId", unfiledRecordFolderId);
mandatory("unfiledRecordFolderInfo", unfiledRecordFolderInfo);
mandatory("parameters", parameters);
NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(unfiledRecordFolderId, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER);
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {
public Void execute() {
apiUtils.updateNode(nodeRef, unfiledRecordFolderInfo, parameters);
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>() {
public FileInfo execute() {
return fileFolderService.getFileInfo(nodeRef);
}
};
FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
apiUtils.postActivity(info, unfiledRecordFolderInfo.getParentId(), ActivityType.FILE_UPDATED);
return nodesModelFactory.createUnfiledRecordFolder(info, parameters, null, false);
}
use of org.alfresco.service.cmr.model.FileInfo in project records-management by Alfresco.
the class ExtendedFileFolderServiceImpl method create.
@Override
public FileInfo create(NodeRef parentNodeRef, String name, QName typeQName, QName assocQName) {
FileInfo result = null;
recordService.disablePropertyEditableCheck();
try {
result = super.create(parentNodeRef, name, typeQName, assocQName);
} finally {
recordService.enablePropertyEditableCheck();
if (result != null) {
recordService.disablePropertyEditableCheck(result.getNodeRef());
}
}
return result;
}
use of org.alfresco.service.cmr.model.FileInfo in project acs-community-packaging by Alfresco.
the class PickerBean method getFolderNodes.
@InvokeCommand.ResponseMimetype(value = MimetypeMap.MIMETYPE_HTML)
public void getFolderNodes() throws Exception {
FacesContext fc = FacesContext.getCurrentInstance();
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
tx.begin();
List<ChildAssociationRef> childRefs;
NodeRef companyHomeRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc));
NodeRef parentRef = null;
Map params = fc.getExternalContext().getRequestParameterMap();
String strChildRef = Utils.encode((String) params.get(PARAM_CHILD));
if (strChildRef != null && strChildRef.length() != 0) {
// TODO: check permission on the parent
NodeRef childRef = new NodeRef(strChildRef);
parentRef = this.getNodeService().getPrimaryParent(childRef).getParentRef();
} else {
// TODO: check permission on the parent
String strParentRef = Utils.encode((String) params.get(PARAM_PARENT));
if (strParentRef == null || strParentRef.length() == 0) {
parentRef = companyHomeRef;
strParentRef = parentRef.toString();
} else {
parentRef = new NodeRef(strParentRef);
}
}
List<FileInfo> folders = this.getFileFolderService().listFolders(parentRef);
JSONWriter out = new JSONWriter(fc.getResponseWriter());
out.startObject();
out.startValue(ID_PARENT);
out.startObject();
out.writeValue(ID_ID, parentRef.toString());
out.writeValue(ID_NAME, Repository.getNameForNode(this.getInternalNodeService(), parentRef));
if (parentRef.equals(companyHomeRef)) {
out.writeValue(ID_ISROOT, true);
}
out.endObject();
out.endValue();
out.startValue(ID_CHILDREN);
out.startArray();
// filter out those children that are not spaces
for (FileInfo folder : folders) {
out.startObject();
out.writeValue(ID_ID, folder.getNodeRef().toString());
out.writeValue(ID_NAME, (String) folder.getProperties().get(ContentModel.PROP_NAME));
String icon = (String) folder.getProperties().get(ApplicationModel.PROP_ICON);
out.writeValue(ID_ICON, FOLDER_IMAGE_PREFIX + (icon != null ? icon + "-16.gif" : BrowseBean.SPACE_SMALL_DEFAULT + ".gif"));
out.endObject();
}
out.endArray();
out.endValue();
out.endObject();
tx.commit();
} catch (Throwable err) {
Utils.addErrorMessage("PickerBean exception in getFolderNodes()", err);
fc.getResponseWriter().write("ERROR: " + err.getMessage());
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
use of org.alfresco.service.cmr.model.FileInfo in project acs-community-packaging by Alfresco.
the class PickerBean method getFileFolderNodes.
/**
* Return the JSON objects representing a list of cm:folder and cm:content nodes.
*
* IN: "parent" - noderef (can be null) of the parent to retrieve the child nodes for. Null is valid
* and specifies the Company Home root as the parent.
* IN: "child" - non-null value of the child noderef to retrieve the siblings for - the parent value returned
* in the JSON response will be the parent of the specified child.
* IN: "mimetypes" (optional) - if set, a comma separated list of mimetypes to restrict the file list.
*
* It is assumed that only files should be selectable, all cm:folder nodes will be marked with the
* 'selectable:false' property. Therefore the parent (which is a folder) is not selectable.
*
* The 16x16 pixel node icon path is output as the 'icon' property for each child, in addition each
* cm:content node has an property of 'url' for content download.
*/
@InvokeCommand.ResponseMimetype(value = MimetypeMap.MIMETYPE_HTML)
public void getFileFolderNodes() throws Exception {
FacesContext fc = FacesContext.getCurrentInstance();
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
tx.begin();
DictionaryService dd = Repository.getServiceRegistry(fc).getDictionaryService();
ContentService cs = Repository.getServiceRegistry(fc).getContentService();
List<ChildAssociationRef> childRefs;
NodeRef companyHomeRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc));
NodeRef parentRef = null;
Map params = fc.getExternalContext().getRequestParameterMap();
String strChildRef = Utils.encode((String) params.get(PARAM_CHILD));
if (strChildRef != null && strChildRef.length() != 0) {
// TODO: check permission on the parent
NodeRef childRef = new NodeRef(strChildRef);
parentRef = this.getNodeService().getPrimaryParent(childRef).getParentRef();
} else {
// TODO: check permission on the parent
String strParentRef = Utils.encode((String) params.get(PARAM_PARENT));
if (strParentRef == null || strParentRef.length() == 0) {
parentRef = companyHomeRef;
strParentRef = parentRef.toString();
} else {
parentRef = new NodeRef(strParentRef);
}
}
// look for mimetype restriction parameter
Set<String> mimetypes = null;
String mimetypeParam = (String) params.get(PARAM_MIMETYPES);
if (mimetypeParam != null && mimetypeParam.length() != 0) {
// convert to a set of mimetypes to test each file against
mimetypes = new HashSet<String>();
for (StringTokenizer t = new StringTokenizer(mimetypeParam, ","); t.hasMoreTokens(); ) /**/
{
mimetypes.add(t.nextToken());
}
}
List<FileInfo> items = this.getFileFolderService().list(parentRef);
JSONWriter out = new JSONWriter(fc.getResponseWriter());
out.startObject();
out.startValue(ID_PARENT);
out.startObject();
out.writeValue(ID_ID, parentRef.toString());
out.writeValue(ID_NAME, Repository.getNameForNode(this.getInternalNodeService(), parentRef));
if (parentRef.equals(companyHomeRef)) {
out.writeValue(ID_ISROOT, true);
}
out.writeValue(ID_SELECTABLE, false);
out.endObject();
out.endValue();
out.startValue(ID_CHILDREN);
out.startArray();
for (FileInfo item : items) {
if (dd.isSubClass(this.getInternalNodeService().getType(item.getNodeRef()), ContentModel.TYPE_FOLDER)) {
// found a folder
out.startObject();
out.writeValue(ID_ID, item.getNodeRef().toString());
String name = (String) item.getProperties().get(ContentModel.PROP_NAME);
out.writeValue(ID_NAME, name);
String icon = (String) item.getProperties().get(ApplicationModel.PROP_ICON);
out.writeValue(ID_ICON, FOLDER_IMAGE_PREFIX + (icon != null ? icon + "-16.gif" : BrowseBean.SPACE_SMALL_DEFAULT + ".gif"));
out.writeValue(ID_SELECTABLE, false);
out.endObject();
} else {
// must be a file
boolean validFile = true;
if (mimetypes != null) {
validFile = false;
ContentReader reader = cs.getReader(item.getNodeRef(), ContentModel.PROP_CONTENT);
if (reader != null) {
String mimetype = reader.getMimetype();
validFile = (mimetype != null && mimetypes.contains(mimetype));
}
}
if (validFile) {
out.startObject();
out.writeValue(ID_ID, item.getNodeRef().toString());
String name = (String) item.getProperties().get(ContentModel.PROP_NAME);
out.writeValue(ID_NAME, name);
String icon = FileTypeImageUtils.getFileTypeImage(fc, name, FileTypeImageSize.Small);
out.writeValue(ID_ICON, icon);
out.writeValue(ID_URL, DownloadContentServlet.generateBrowserURL(item.getNodeRef(), name));
out.endObject();
}
}
}
out.endArray();
out.endValue();
out.endObject();
tx.commit();
} catch (Throwable err) {
Utils.addErrorMessage("PickerBean exception in getFileFolderNodes()", err);
fc.getResponseWriter().write("ERROR: " + err.getMessage());
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
use of org.alfresco.service.cmr.model.FileInfo in project acs-community-packaging by Alfresco.
the class BrowseBean method getParentNodes.
/**
* Page accessed bean method to get the parent container nodes currently being browsed
*
* @return List of parent container Node objects for the current browse location
*/
public List<Node> getParentNodes(NodeRef currNodeRef) {
if (this.parentContainerNodes == null) {
long startTime = 0;
if (logger.isDebugEnabled())
startTime = System.currentTimeMillis();
UserTransaction tx = null;
try {
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context, true);
tx.begin();
NodeRef parentRef = getNodeService().getPrimaryParent(currNodeRef).getParentRef();
List<FileInfo> children = this.getFileFolderService().list(parentRef);
this.parentContainerNodes = new ArrayList<Node>(children.size());
for (FileInfo fileInfo : children) {
// create our Node representation from the NodeRef
NodeRef nodeRef = fileInfo.getNodeRef();
// find it's type so we can see if it's a node we are interested in
QName type = this.getNodeService().getType(nodeRef);
// make sure the type is defined in the data dictionary
TypeDefinition typeDef = this.getDictionaryService().getType(type);
if (typeDef != null) {
MapNode node = null;
// look for Space folder node
if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) == true && this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
// create our Node representation
node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
node.addPropertyResolver("icon", this.resolverSpaceIcon);
node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
this.parentContainerNodes.add(node);
} else if (ApplicationModel.TYPE_FOLDERLINK.equals(type)) {
// create our Folder Link Node representation
node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
node.addPropertyResolver("icon", this.resolverSpaceIcon);
node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
this.parentContainerNodes.add(node);
}
} else {
if (logger.isWarnEnabled())
logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type);
}
}
// commit the transaction
tx.commit();
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }), refErr);
this.parentContainerNodes = Collections.<Node>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
this.parentContainerNodes = Collections.<Node>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
if (logger.isDebugEnabled()) {
long endTime = System.currentTimeMillis();
logger.debug("Time to query and build map parent nodes: " + (endTime - startTime) + "ms");
}
}
List<Node> result = this.parentContainerNodes;
return result;
}
Aggregations