use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.
the class BrowseBean method queryBrowseNodes.
// ------------------------------------------------------------------------------
// Helper methods
/**
* Query a list of nodes for the specified parent node Id
*
* @param parentNodeId Id of the parent node or null for the root node
*/
private void queryBrowseNodes(String parentNodeId) {
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;
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<FileInfo> children = null;
FileFilterMode.setClient(Client.webclient);
try {
children = this.getFileFolderService().list(parentRef);
} finally {
FileFilterMode.clearClient();
}
this.containerNodes = new ArrayList<Node>(children.size());
this.contentNodes = new ArrayList<Node>(children.size());
// in case of dynamic config, only lookup once
Set<NodeEventListener> nodeEventListeners = getNodeEventListeners();
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 File content node
if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT)) {
// create our Node representation
node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
setupCommonBindingProperties(node);
this.contentNodes.add(node);
} else // 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.containerNodes.add(node);
} else // look for File Link object node
if (ApplicationModel.TYPE_FILELINK.equals(type)) {
// create our File Link Node representation
node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
// only display the user has the permissions to navigate to the target of the link
NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
if (destRef != null && new Node(destRef).hasPermission(PermissionService.READ) == true) {
node.addPropertyResolver("url", this.resolverLinkUrl);
node.addPropertyResolver("downloadUrl", this.resolverLinkDownload);
node.addPropertyResolver("webdavUrl", this.resolverLinkWebdavUrl);
node.addPropertyResolver("cifsPath", this.resolverLinkCifsPath);
node.addPropertyResolver("fileType16", this.resolverFileType16);
node.addPropertyResolver("fileType32", this.resolverFileType32);
node.addPropertyResolver("lang", this.resolverLang);
this.contentNodes.add(node);
}
} else if (ApplicationModel.TYPE_FOLDERLINK.equals(type)) {
// create our Folder Link Node representation
node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
// only display the user has the permissions to navigate to the target of the link
NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
if (destRef != null && new Node(destRef).hasPermission(PermissionService.READ) == true) {
node.addPropertyResolver("icon", this.resolverSpaceIcon);
node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
this.containerNodes.add(node);
}
}
// inform any listeners that a Node wrapper has been created
if (node != null) {
for (NodeEventListener listener : nodeEventListeners) {
listener.created(node, type);
}
}
} 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.containerNodes = Collections.<Node>emptyList();
this.contentNodes = 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.containerNodes = Collections.<Node>emptyList();
this.contentNodes = 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 nodes: " + (endTime - startTime) + "ms");
}
}
use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.
the class BrowseBean method setupContentAction.
/**
* Public helper to setup action pages with content context
*
* @param id of the content node to setup context for
*/
public void setupContentAction(String id, boolean invalidate) {
if (id != null && id.length() != 0) {
if (logger.isDebugEnabled())
logger.debug("Setup for action, setting current document to: " + id);
try {
// create the node ref, then our node representation
NodeRef ref = new NodeRef(Repository.getStoreRef(), id);
Node node = new MapNode(ref);
// store the URL to for downloading the content
if (ApplicationModel.TYPE_FILELINK.equals(node.getType())) {
node.addPropertyResolver("url", this.resolverLinkDownload);
node.addPropertyResolver("downloadUrl", this.resolverLinkDownload);
} else {
node.addPropertyResolver("url", this.resolverDownload);
node.addPropertyResolver("downloadUrl", this.resolverDownload);
}
node.addPropertyResolver("webdavUrl", this.resolverWebdavUrl);
node.addPropertyResolver("cifsPath", this.resolverCifsPath);
node.addPropertyResolver("fileType32", this.resolverFileType32);
node.addPropertyResolver("mimetype", this.resolverMimetype);
node.addPropertyResolver("encoding", this.resolverEncoding);
node.addPropertyResolver("size", this.resolverSize);
node.addPropertyResolver("lang", this.resolverLang);
for (NodeEventListener listener : getNodeEventListeners()) {
listener.created(node, node.getType());
}
// get hold of the DocumentDetailsDialog and reset it
DocumentDetailsDialog docDetails = (DocumentDetailsDialog) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("DocumentDetailsDialog");
if (docDetails != null) {
docDetails.reset();
}
// remember the document
setDocument(node);
// setup the dispatch context in case it is required
this.navigator.setupDispatchContext(node);
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
throw new AbortProcessingException("Invalid node reference");
}
} else {
setDocument(null);
}
// clear the UI state in preparation for finishing the next action
if (invalidate == true) {
// use the context service to notify all registered beans
UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
}
}
use of org.alfresco.web.bean.repository.MapNode 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.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.
the class MultilingualManageDialog method initEditionHistory.
/**
* Constructs a list of objects representing the editions of the
* logical document
*
* @return List of editions
*/
private List<SingleEditionBean> initEditionHistory() {
// get the mlContainer
NodeRef mlContainer = getDocumentMlContainer().getNodeRef();
// get all editions (in descending order - ie. most recent first)
List<Version> orderedEditionList = new ArrayList<Version>(getEditionService().getEditions(mlContainer).getAllVersions());
// the list of Single Edition Bean to return
editionHistory = new ArrayList<SingleEditionBean>(orderedEditionList.size());
boolean firstEdition = true;
// for each edition, init a SingleEditionBean
for (Version edition : orderedEditionList) {
SingleEditionBean editionBean = new SingleEditionBean();
MapNode clientEdition = new MapNode(edition.getFrozenStateNodeRef());
String editionLabel = edition.getVersionLabel();
if (firstEdition) {
editionLabel += " (" + Application.getMessage(FacesContext.getCurrentInstance(), MSG_CURRENT) + ")";
}
clientEdition.put("editionLabel", editionLabel);
clientEdition.put("editionNotes", edition.getDescription());
clientEdition.put("editionAuthor", edition.getCreator());
clientEdition.put("editionDate", edition.getCreatedDate());
// Set the edition of the edition bean
editionBean.setEdition(clientEdition);
// get translations
List<VersionHistory> translationHistories = null;
if (firstEdition) {
// Get the translations because the current edition doesn't content link with its
// translation in the version store.
Map<Locale, NodeRef> translations = getMultilingualContentService().getTranslations(mlContainer);
translationHistories = new ArrayList<VersionHistory>(translations.size());
for (NodeRef translation : translations.values()) {
translationHistories.add(getVersionService().getVersionHistory(translation));
}
} else {
translationHistories = getEditionService().getVersionedTranslations(edition);
}
// add each translation in the SingleEditionBean
for (VersionHistory versionHistory : translationHistories) {
for (Version checkVersion : versionHistory.getAllVersions()) {
NodeRef frozenStateNodeRef = checkVersion.getFrozenStateNodeRef();
if (frozenStateNodeRef.getStoreRef().getIdentifier().equals("lightWeightVersionStore")) {
// It's the old one pulled back by serialization
// Repopulate the version history
NodeRef versionedNodeRef = checkVersion.getVersionedNodeRef();
versionHistory = versionService.getVersionHistory(versionedNodeRef);
break;
}
}
// get the list of versions (in descending order - ie. most recent first)
List<Version> orderedVersions = new ArrayList<Version>(versionHistory.getAllVersions());
// the last version (ie. most recent) is the first version of the list
Version lastVersion = orderedVersions.get(0);
// get the properties of the lastVersion
Map<QName, Serializable> lastVersionProperties = getEditionService().getVersionedMetadatas(lastVersion);
Locale language = (Locale) lastVersionProperties.get(ContentModel.PROP_LOCALE);
// create a map node representation of the last version
MapNode clientLastVersion = new MapNode(lastVersion.getFrozenStateNodeRef());
clientLastVersion.put("versionName", lastVersionProperties.get(ContentModel.PROP_NAME));
// use the node service for the description to ensure that the returned value is a text and not a MLText
clientLastVersion.put("versionDescription", getNodeService().getProperty(lastVersion.getFrozenStateNodeRef(), ContentModel.PROP_DESCRIPTION));
clientLastVersion.put("versionAuthor", lastVersionProperties.get(ContentModel.PROP_AUTHOR));
clientLastVersion.put("versionCreatedDate", lastVersionProperties.get(ContentModel.PROP_CREATED));
clientLastVersion.put("versionModifiedDate", lastVersionProperties.get(ContentModel.PROP_MODIFIED));
clientLastVersion.put("versionLanguage", getContentFilterLanguagesService().convertToNewISOCode(language.getLanguage()).toUpperCase());
if (getNodeService().hasAspect(lastVersion.getFrozenStateNodeRef(), ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)) {
clientLastVersion.put("versionUrl", null);
} else {
clientLastVersion.put("versionUrl", DownloadContentServlet.generateBrowserURL(lastVersion.getFrozenStateNodeRef(), clientLastVersion.getName()));
}
// add a translation of the editionBean
editionBean.addTranslations(clientLastVersion);
}
editionHistory.add(editionBean);
firstEdition = false;
}
return editionHistory;
}
use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.
the class ManageTaskDialog method createAndAddNode.
// ------------------------------------------------------------------------------
// Helper methods
protected void createAndAddNode(NodeRef nodeRef) {
// create our Node representation
MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
this.browseBean.setupCommonBindingProperties(node);
// add property resolvers to show path information
node.addPropertyResolver("path", this.browseBean.resolverPath);
node.addPropertyResolver("displayPath", this.browseBean.resolverDisplayPath);
// add a property resolver to indicate whether the item has been
// completed or not
// node.addPropertyResolver("completed", this.completeResolver);
// add the id of the task being managed
node.getProperties().put("taskId", this.getWorkflowTask().id);
this.resources.add(node);
}
Aggregations