use of org.alfresco.service.cmr.dictionary.DictionaryService in project alfresco-remote-api by Alfresco.
the class AdminWebScriptTest method testResidualProperties.
@Test
public // ALF-21950 We check now if the property belongs to the type of the node
void testResidualProperties() throws Exception {
NodeBrowserPost nodeBrowserPost = new NodeBrowserPost();
DictionaryService dictionaryService = mock(DictionaryService.class);
NodeService nodeService = mock(NodeService.class);
nodeBrowserPost.setDictionaryService(dictionaryService);
nodeBrowserPost.setNodeService(nodeService);
// make own class definition from origin type
ClassDefinition classDefinition = mock(ClassDefinition.class);
when(dictionaryService.getClass(any())).thenReturn(classDefinition);
QName qnameResidualFalse1 = QName.createQName("testResidualProperties", "residualFalse1");
QName qnameResidualFalse2 = QName.createQName("testResidualProperties", "residualFalse2");
QName qnameResidualTrue1 = QName.createQName("testResidualProperties", "residualTrue1");
QName qnameResidualTrue2 = QName.createQName("testResidualProperties", "residualTrue2");
// Define residual False properties inside of class definition
// That simulates the belonging of the properties to a given type of a node
Map<QName, PropertyDefinition> properties = new HashMap<>();
properties.put(qnameResidualFalse1, new SimplePropertyDefinition(false));
properties.put(qnameResidualFalse2, new SimplePropertyDefinition(true));
when(classDefinition.getProperties()).thenReturn(properties);
when(dictionaryService.getProperty(eq(qnameResidualFalse1))).thenReturn(new SimplePropertyDefinition(false));
when(dictionaryService.getProperty(eq(qnameResidualFalse2))).thenReturn(new SimplePropertyDefinition(true));
when(dictionaryService.getProperty(eq(qnameResidualTrue1))).thenReturn(new SimplePropertyDefinition(true));
when(dictionaryService.getProperty(eq(qnameResidualTrue2))).thenReturn(new SimplePropertyDefinition(false));
// property found in definition so it is not residual
String value = "abc";
NodeBrowserPost.Property property = nodeBrowserPost.new Property(qnameResidualFalse1, value, null);
assertFalse(property.getResidual());
// property belongs to an aspect so it is not residual
property = nodeBrowserPost.new Property(qnameResidualFalse2, value, null);
assertFalse(property.getResidual());
// property not found in definition but it is an aspect so it is not residual
property = nodeBrowserPost.new Property(qnameResidualTrue1, value, null);
assertFalse(property.getResidual());
// property not found in definition so it is residual
property = nodeBrowserPost.new Property(qnameResidualTrue2, value, null);
assertTrue(property.getResidual());
}
use of org.alfresco.service.cmr.dictionary.DictionaryService in project acs-community-packaging by Alfresco.
the class TemplateSupportBean method selectDictionaryNodes.
/**
* @param fc FacesContext
* @param xpath XPath to the nodes to select
* @param noSelectionLabel Label to add to the list if no items are found in the search
* @param mimetype Optional mimetype of items to add, will not add to list if mimetype does not match
*
* @return List of SelectItem wrapper objects for the nodes found at the XPath
*/
private List<SelectItem> selectDictionaryNodes(FacesContext fc, String xpath, String noSelectionLabel, String mimetype) {
List<SelectItem> wrappers = null;
try {
NodeRef rootNodeRef = this.getNodeService().getRootNode(Repository.getStoreRef());
NamespaceService resolver = Repository.getServiceRegistry(fc).getNamespaceService();
List<NodeRef> results = this.getSearchService().selectNodes(rootNodeRef, xpath, null, resolver, false);
wrappers = new ArrayList<SelectItem>(results.size() + 1);
if (results.size() != 0) {
DictionaryService dd = Repository.getServiceRegistry(fc).getDictionaryService();
for (NodeRef ref : results) {
if (this.getNodeService().exists(ref) == true) {
Node childNode = new Node(ref);
ContentData content = (ContentData) childNode.getProperties().get(ContentModel.PROP_CONTENT);
if (dd.isSubClass(childNode.getType(), ContentModel.TYPE_CONTENT) && (mimetype == null || mimetype.equals(content.getMimetype()))) {
wrappers.add(new SelectItem(childNode.getId(), childNode.getName()));
}
}
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(wrappers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
} catch (AccessDeniedException accessErr) {
// ignore the result if we cannot access the root
}
// add an entry (at the start) to instruct the user to select an item
if (wrappers == null) {
wrappers = new ArrayList<SelectItem>(1);
}
wrappers.add(0, new SelectItem(NO_SELECTION, Application.getMessage(FacesContext.getCurrentInstance(), noSelectionLabel)));
return wrappers;
}
use of org.alfresco.service.cmr.dictionary.DictionaryService in project acs-community-packaging by Alfresco.
the class WorkspaceClipboardItem method paste.
/**
* @see org.alfresco.web.bean.clipboard.ClipboardItem#paste(javax.faces.context.FacesContext, java.lang.String, int)
*/
public boolean paste(final FacesContext fc, String viewId, final int action) {
final ServiceRegistry serviceRegistry = getServiceRegistry();
final RetryingTransactionHelper retryingTransactionHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
if (super.canCopyToViewId(viewId) || WORKSPACE_PASTE_VIEW_ID.equals(viewId) || FORUMS_PASTE_VIEW_ID.equals(viewId) || FORUM_PASTE_VIEW_ID.equals(viewId)) {
NavigationBean navigator = (NavigationBean) FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME);
final NodeRef destRef = new NodeRef(Repository.getStoreRef(), navigator.getCurrentNodeId());
final DictionaryService dd = serviceRegistry.getDictionaryService();
final NodeService nodeService = serviceRegistry.getNodeService();
final FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
final CopyService copyService = serviceRegistry.getCopyService();
final MultilingualContentService multilingualContentService = serviceRegistry.getMultilingualContentService();
final boolean isPrimaryParent;
final ChildAssociationRef assocRef;
if (getParent() == null) {
assocRef = nodeService.getPrimaryParent(getNodeRef());
isPrimaryParent = true;
} else {
NodeRef parentNodeRef = getParent();
List<ChildAssociationRef> assocList = nodeService.getParentAssocs(getNodeRef());
ChildAssociationRef foundRef = null;
if (assocList != null) {
for (ChildAssociationRef assocListEntry : assocList) {
if (parentNodeRef.equals(assocListEntry.getParentRef())) {
foundRef = assocListEntry;
break;
}
}
}
assocRef = foundRef;
isPrimaryParent = parentNodeRef.equals(nodeService.getPrimaryParent(getNodeRef()).getParentRef());
}
// initial name to attempt the copy of the item with
String name = getName();
String translationPrefix = "";
if (action == UIClipboardShelfItem.ACTION_PASTE_LINK) {
// copy as link was specifically requested by the user
String linkTo = Application.getMessage(fc, MSG_LINK_TO);
name = linkTo + ' ' + name;
}
// Loop until we find a target name that doesn't exist
for (; ; ) {
try {
final String currentTranslationPrefix = translationPrefix;
final String currentName = name;
// attempt each copy/paste in its own transaction
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
if (getMode() == ClipboardStatus.COPY) {
if (action == UIClipboardShelfItem.ACTION_PASTE_LINK) {
// LINK operation
if (logger.isDebugEnabled())
logger.debug("Attempting to link node ID: " + getNodeRef() + " into node: " + destRef.toString());
// create the node using the nodeService (can only use FileFolderService for content)
if (checkExists(currentName + LINK_NODE_EXTENSION, destRef) == false) {
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
String newName = currentName + LINK_NODE_EXTENSION;
props.put(ContentModel.PROP_NAME, newName);
props.put(ContentModel.PROP_LINK_DESTINATION, getNodeRef());
if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT)) {
// create File Link node
ChildAssociationRef childRef = nodeService.createNode(destRef, ContentModel.ASSOC_CONTAINS, QName.createQName(assocRef.getQName().getNamespaceURI(), newName), ApplicationModel.TYPE_FILELINK, props);
// apply the titled aspect - title and description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(2, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, currentName);
titledProps.put(ContentModel.PROP_DESCRIPTION, currentName);
nodeService.addAspect(childRef.getChildRef(), ContentModel.ASPECT_TITLED, titledProps);
} else {
// create Folder link node
ChildAssociationRef childRef = nodeService.createNode(destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName(), ApplicationModel.TYPE_FOLDERLINK, props);
// apply the uifacets aspect - icon, title and description props
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(4, 1.0f);
uiFacetsProps.put(ApplicationModel.PROP_ICON, "space-icon-link");
uiFacetsProps.put(ContentModel.PROP_TITLE, currentName);
uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, currentName);
nodeService.addAspect(childRef.getChildRef(), ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
}
}
} else {
// COPY operation
if (logger.isDebugEnabled())
logger.debug("Attempting to copy node: " + getNodeRef() + " into node ID: " + destRef.toString());
// first check that we are not attempting to copy a duplicate into the same parent
if (destRef.equals(assocRef.getParentRef()) && currentName.equals(getName())) {
// manually change the name if this occurs
throw new FileExistsException(destRef, currentName);
}
if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT) || dd.isSubClass(getType(), ContentModel.TYPE_FOLDER)) {
// copy the file/folder
fileFolderService.copy(getNodeRef(), destRef, currentName);
} else if (dd.isSubClass(getType(), ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
// copy the mlContainer and its translations
multilingualContentService.copyTranslationContainer(getNodeRef(), destRef, currentTranslationPrefix);
} else {
// copy the node
if (checkExists(currentName, destRef) == false) {
copyService.copyAndRename(getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName(), true);
}
}
}
} else {
// MOVE operation
if (logger.isDebugEnabled())
logger.debug("Attempting to move node: " + getNodeRef() + " into node ID: " + destRef.toString());
if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT) || dd.isSubClass(getType(), ContentModel.TYPE_FOLDER)) {
// move the file/folder
fileFolderService.moveFrom(getNodeRef(), getParent(), destRef, currentName);
} else if (dd.isSubClass(getType(), ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
// copy the mlContainer and its translations
multilingualContentService.moveTranslationContainer(getNodeRef(), destRef);
} else {
if (isPrimaryParent) {
// move the node
nodeService.moveNode(getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName());
} else {
nodeService.removeChild(getParent(), getNodeRef());
nodeService.addChild(destRef, getNodeRef(), assocRef.getTypeQName(), assocRef.getQName());
}
}
}
return null;
}
});
// We got here without error, so no need to loop with a new name
break;
} catch (FileExistsException fileExistsErr) {
// If mode is COPY, have another go around the loop with a new name
if (getMode() == ClipboardStatus.COPY) {
String copyOf = Application.getMessage(fc, MSG_COPY_OF);
name = copyOf + ' ' + name;
translationPrefix = copyOf + ' ' + translationPrefix;
} else {
// we should not rename an item when it is being moved - so exit
throw fileExistsErr;
}
}
}
return true;
} else {
return false;
}
}
use of org.alfresco.service.cmr.dictionary.DictionaryService in project acs-community-packaging by Alfresco.
the class UINodeWorkflowInfo method encodeBegin.
@Override
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
if (!isRendered())
return;
// get the node to display the information for
Node node = getValue();
if (node != null) {
// get the services we need
NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
DictionaryService ddService = Repository.getServiceRegistry(context).getDictionaryService();
WorkflowService workflowService = Repository.getServiceRegistry(context).getWorkflowService();
ResponseWriter out = context.getResponseWriter();
ResourceBundle bundle = Application.getBundle(context);
// render simple workflow info
renderSimpleWorkflowInfo(context, node, nodeService, ddService, out, bundle);
// render advanced workflow info
renderAdvancedWorkflowInfo(context, node, nodeService, ddService, workflowService, out, bundle);
}
}
use of org.alfresco.service.cmr.dictionary.DictionaryService in project acs-community-packaging by Alfresco.
the class UISpaceSelector method getChildrenForNode.
public Collection<NodeRef> getChildrenForNode(FacesContext context) {
NodeRef nodeRef = new NodeRef(Repository.getStoreRef(), this.navigationId);
List<ChildAssociationRef> allKids = getNodeService(context).getChildAssocs(nodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
DictionaryService dd = getDictionaryService(context);
NodeService service = getFastNodeService(context);
// filter out those children that are not spaces
List<NodeRef> spaceKids = new ArrayList<NodeRef>();
for (ChildAssociationRef ref : allKids) {
if (dd.isSubClass(service.getType(ref.getChildRef()), ContentModel.TYPE_FOLDER) && dd.isSubClass(service.getType(ref.getChildRef()), ContentModel.TYPE_SYSTEM_FOLDER) == false) {
spaceKids.add(ref.getChildRef());
}
}
return spaceKids;
}
Aggregations