use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.
the class NewUserWizard method populate.
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#populate()
*/
public void populate() {
// set values for edit mode
Map<String, Object> props = getPerson().getProperties();
this.firstName = (String) props.get("firstName");
this.lastName = (String) props.get("lastName");
this.userName = (String) props.get("userName");
this.password = "";
this.confirm = "";
this.email = (String) props.get("email");
this.companyId = (String) props.get("organizationId");
// calculate home space name and parent space Id from homeFolderId
// default to Company root space
this.homeSpaceLocation = null;
// default to none set below root
this.homeSpaceName = "";
NodeRef homeFolderRef = (NodeRef) props.get("homeFolder");
if (homeFolderRef != null && this.getNodeService().exists(homeFolderRef) == true) {
ChildAssociationRef childAssocRef = this.getNodeService().getPrimaryParent(homeFolderRef);
NodeRef parentRef = childAssocRef.getParentRef();
if (this.getNodeService().getRootNode(Repository.getStoreRef()).equals(parentRef) == false) {
this.homeSpaceLocation = parentRef;
this.homeSpaceName = Repository.getNameForNode(getNodeService(), homeFolderRef);
} else {
this.homeSpaceLocation = homeFolderRef;
}
}
if (logger.isDebugEnabled())
logger.debug("Edit user home space location: " + homeSpaceLocation + " home space name: " + homeSpaceName);
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.
the class TrashcanDialog method buildItemsTable.
/**
* Build an HTML table of the items that are to be or have been recovered.
*
* @param items List of Node objects to display in the table
* @param cssClass CSS style to apply to the table
* @param report Set true to report the reason for any failure. This flag requires that the Node
* object has a pseudo property "recoverstatus" containing the RestoreStatus.
* @param archivedPath Set true to show the path from the 'sys:archivedOriginalParentAssoc' property,
* else the current Node Path will be used.
*
* @return HTML table of node info
*/
private String buildItemsTable(List<Node> items, String cssClass, boolean report, boolean archivedPath) {
FacesContext fc = FacesContext.getCurrentInstance();
String contextPath = fc.getExternalContext().getRequestContextPath();
StringBuilder buf = new StringBuilder(1024);
// outer table
buf.append("<table width=100% cellspacing=1 cellpadding=1 border=0 class='");
buf.append(cssClass);
buf.append("'>");
// title row
buf.append("<tr style='border-bottom:1px'><th></th><th align=left><b>");
buf.append(Application.getMessage(fc, MSG_NAME));
buf.append("</b></th>");
if (report == true) {
buf.append("<th align=left>");
buf.append(Application.getMessage(fc, MSG_RECOVERY_REASON));
buf.append("</th>");
} else {
buf.append("<th align=left><b>");
buf.append(Application.getMessage(fc, MSG_LOCATION));
buf.append("</b></th>");
}
buf.append("</tr>");
for (Node node : items) {
// listed item rows
buf.append("<tr><td width=16>");
String img;
if (getDictionaryService().isSubClass(node.getType(), ContentModel.TYPE_FOLDER)) {
String icon = (String) node.getProperties().get("app:icon");
img = "/images/icons/" + (icon != null ? icon + "-16.gif" : BrowseBean.SPACE_SMALL_DEFAULT + ".gif");
} else {
img = FileTypeImageUtils.getFileTypeImage(node.getName(), true);
}
buf.append("<img width=16 height=16 alt='' src='").append(contextPath).append(img).append("'>");
buf.append("</td><td>");
buf.append(Utils.encode(node.getName()));
buf.append("</td>");
if (report) {
buf.append("<td>");
String msg;
RestoreStatus status = (RestoreStatus) node.getProperties().get(PROP_RECOVERSTATUS);
String message = (String) node.getProperties().get(PROP_RECOVERERRORMESSAGE);
switch(status) {
case FAILURE_INVALID_PARENT:
msg = MSG_RECOVERED_ITEM_PARENT_S;
break;
case FAILURE_PERMISSION:
msg = MSG_RECOVERED_ITEM_PERMISSION_S;
break;
case FAILURE_INTEGRITY:
msg = MSG_RECOVERED_ITEM_INTEGRITY_S;
break;
case FAILURE_DUPLICATE_CHILD_NODE_NAME:
msg = MSG_RECOVERED_ITEM_DUPLICATE_S;
break;
default:
msg = MSG_RECOVERED_ITEM_FAILURE_S;
break;
}
buf.append(Application.getMessage(fc, msg));
buf.append(": ");
buf.append(message);
buf.append("</td>");
} else {
buf.append("<td>");
if (archivedPath) {
ChildAssociationRef childRef = (ChildAssociationRef) node.getProperties().get(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
if (getNodeService().exists(childRef.getParentRef())) {
buf.append(Utils.encode(Repository.getNamePath(getNodeService(), getNodeService().getPath(childRef.getParentRef()), null, "/", null)));
}
} else {
buf.append(Utils.encode(Repository.getNamePath(getNodeService(), getNodeService().getPath(node.getNodeRef()), null, "/", null)));
}
buf.append("</td>");
}
buf.append("</tr>");
}
// end table
buf.append("</table>");
return buf.toString();
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.
the class Node method getChildAssociations.
/**
* @return All the child associations this node has as a Map, using the association
* type as the key
*/
public final Map getChildAssociations() {
if (this.childAssocsRetrieved == false) {
this.childAssociations = new QNameNodeMap(this, this);
List<ChildAssociationRef> assocs = getServiceRegistry().getNodeService().getChildAssocs(this.nodeRef);
for (ChildAssociationRef assocRef : assocs) {
String assocName = assocRef.getTypeQName().toString();
List list = (List) this.childAssociations.get(assocName);
// create the list if this is first association with 'assocName'
if (list == null) {
list = new ArrayList<ChildAssociationRef>();
this.childAssociations.put(assocName, list);
}
// add the association to the list
list.add(assocRef);
}
this.childAssocsRetrieved = true;
}
return this.childAssociations;
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.
the class ForumsBean method getNodes.
private void getNodes() {
long startTime = 0;
if (logger.isDebugEnabled())
startTime = System.currentTimeMillis();
UserTransaction tx = null;
try {
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context, true);
tx.begin();
// get the current space from NavigationBean
String parentNodeId = this.navigator.getCurrentNodeId();
NodeRef parentRef;
if (parentNodeId == null) {
// no specific parent node specified - use the root node
parentRef = this.getNodeService().getRootNode(Repository.getStoreRef());
} else {
// build a NodeRef for the specified Id and our store
parentRef = new NodeRef(Repository.getStoreRef(), parentNodeId);
}
List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(parentRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
this.forums = new ArrayList<Node>(childRefs.size());
this.topics = new ArrayList<Node>(childRefs.size());
this.posts = new ArrayList<Node>(childRefs.size());
for (ChildAssociationRef ref : childRefs) {
// create our Node representation from the NodeRef
NodeRef nodeRef = ref.getChildRef();
if (this.getNodeService().exists(nodeRef)) {
// 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) {
if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
if (this.getDictionaryService().isSubClass(type, ForumModel.TYPE_FORUMS) || this.getDictionaryService().isSubClass(type, ForumModel.TYPE_FORUM)) {
// create our Node representation
MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
node.addPropertyResolver("icon", this.browseBean.resolverSpaceIcon);
node.addPropertyResolver("smallIcon", this.browseBean.resolverSmallIcon);
this.forums.add(node);
}
if (this.getDictionaryService().isSubClass(type, ForumModel.TYPE_TOPIC)) {
// create our Node representation
MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
node.addPropertyResolver("icon", this.browseBean.resolverSpaceIcon);
node.addPropertyResolver("smallIcon", this.browseBean.resolverSmallIcon);
node.addPropertyResolver("replies", this.resolverReplies);
this.topics.add(node);
} else if (this.getDictionaryService().isSubClass(type, ForumModel.TYPE_POST)) {
// create our Node representation
MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
this.browseBean.setupCommonBindingProperties(node);
node.addPropertyResolver("smallIcon", this.browseBean.resolverSmallIcon);
node.addPropertyResolver("message", this.resolverContent);
node.addPropertyResolver("replyTo", this.resolverReplyTo);
this.posts.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() }));
this.forums = Collections.<Node>emptyList();
this.topics = Collections.<Node>emptyList();
this.posts = 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.forums = Collections.<Node>emptyList();
this.topics = Collections.<Node>emptyList();
this.posts = 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 forums nodes: " + (endTime - startTime) + "ms");
}
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.
the class DeleteTopicDialog method finishImpl.
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
// find out what the parent type of the node being deleted
Node node = this.browseBean.getActionSpace();
ChildAssociationRef assoc = this.getNodeService().getPrimaryParent(node.getNodeRef());
if (assoc != null) {
NodeRef parent = assoc.getParentRef();
QName parentType = this.getNodeService().getType(parent);
if (parentType.equals(ForumModel.TYPE_FORUM)) {
this.reDisplayTopics = true;
}
}
return super.finishImpl(context, outcome);
}
Aggregations