/** * Actualitza el tamany de la sèrie. * * @param nodeRef * @param parentNodeRef */ private void updateSerie(NodeService nodeService, NodeRef nodeRef, NodeRef serieNodeRef) { System.out.println( DateFormat.getInstance().format(new Date()) + " START: Recalcular tamany sèrie."); int tamany = 0; List<ChildAssociationRef> children = nodeService.getChildAssocs(serieNodeRef); for (ChildAssociationRef childAssoc : children) { NodeRef childNodeRef = childAssoc.getChildRef(); if (nodeService.hasAspect(childNodeRef, expedientRM)) { Serializable tamanySerial = nodeService.getProperty(childNodeRef, tamanyExpedientRM); if (tamanySerial != null) { tamany = tamany + (Integer.parseInt((String) tamanySerial)); } } else if (nodeService.hasAspect(childNodeRef, agregacioRM)) { Serializable tamanySerial = nodeService.getProperty(childNodeRef, tamanyAgregacioRM); if (tamanySerial != null) { tamany = tamany + (Integer.parseInt((String) tamanySerial)); } } } nodeService.setProperty(serieNodeRef, tamanySerieRM, String.valueOf(tamany)); Date now = new Date(); System.out.println( DateFormat.getInstance().format(now) + " Update tamany sèrie: " + serieNodeRef); System.out.println(DateFormat.getInstance().format(now) + " END: Recalcular tamany sèrie."); }
/** * Helper to convert a path into an indexed path which uniquely identifies a node * * @param nodeRef * @param path * @return */ private Path createIndexedPath(NodeRef nodeRef, Path path) { // Add indexes for same name siblings // TODO: Look at more efficient approach for (int i = path.size() - 1; i >= 0; i--) { Path.Element pathElement = path.get(i); if (i > 0 && pathElement instanceof Path.ChildAssocElement) { int index = 1; // for xpath index compatibility String searchPath = path.subPath(i).toPrefixString(namespaceService); List<NodeRef> siblings = searchService.selectNodes(nodeRef, searchPath, null, namespaceService, false); if (siblings.size() > 1) { ChildAssociationRef childAssoc = ((Path.ChildAssocElement) pathElement).getRef(); NodeRef childRef = childAssoc.getChildRef(); for (NodeRef sibling : siblings) { if (sibling.equals(childRef)) { childAssoc.setNthSibling(index); break; } index++; } } } } return path; }
@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(); NodeRef parent = null; ChildAssociationRef assoc = this.getNodeService().getPrimaryParent(node.getNodeRef()); if (assoc != null) { // get the parent node parent = assoc.getParentRef(); // if the parent type is a forum space then we need the dialog to go // back to the forums view otherwise it will use the default of 'browse', // this happens when a forum being used to discuss a node is deleted. QName parentType = this.getNodeService().getType(parent); if (parentType.equals(ForumModel.TYPE_FORUMS)) { this.reDisplayForums = true; } } // delete the forum itself outcome = super.finishImpl(context, outcome); // remove the discussable aspect if appropriate if (assoc != null && parent != null) { // get the association type QName type = assoc.getTypeQName(); if (type.equals(ForumModel.ASSOC_DISCUSSION)) { // if the association type is the 'discussion' association we // need to remove the discussable aspect from the parent node this.getNodeService().removeAspect(parent, ForumModel.ASPECT_DISCUSSABLE); } } return outcome; }
@Override public IAfSysObject moveTo(String specific, String newName) throws AfException { if (isNew()) { throw new AfException("this object is new, you can not move it"); } NodeService nodeService = ServiceHelper.getNodeService(afSession); NodeRef newParent = getSpecifiedNode(specific); if (newParent == null || !(nodeService.exists(newParent))) { throw new AfException("the folder " + specific + " you specified does not exist"); } IAfType folderType = AFCHelper.getNodeType(afSession, newParent); if (!(folderType.isSubTypeOf("cm:folder") || folderType.getName().equals("cm:folder"))) { // parent is a doc throw new AfException("you can not move object into a document"); } String objName = (newName == null) ? getObjectName() : newName; QName nodeName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, objName); ChildAssociationRef child = nodeService.moveNode(nodeRef, newParent, getAssType(), nodeName); IAfSysObject doc = (IAfSysObject) afSession.getObject(new AfID(child.getChildRef().getId())); doc.setObjectName(objName); doc.save(); return doc; }
private static NodeRef followAssociations( ServiceRegistry services, ChildAssociationRef association, QName qnameType, String[] navigation, int indexNavigation) throws InvalidAssociationException, InvalidContentException { NodeRef finalTarget = null; String uri = qnameType.getNamespaceURI(); if (association.getQName().toString().contains(uri) && association.getQName().toString().contains(navigation[indexNavigation])) { NodeRef target = association.getChildRef(); if (target != null) { if (indexNavigation < navigation.length - 2) { QName targetType = services.getNodeService().getType(target); List<ChildAssociationRef> nextAssociations = services.getNodeService().getChildAssocs(target); for (ChildAssociationRef nextAssociation : nextAssociations) { followAssociations( services, nextAssociation, targetType, navigation, indexNavigation++); } } else { finalTarget = target; } } else { throw new InvalidContentException(InvalidContentException.DOES_NOT_EXISTS); } } else { throw new InvalidAssociationException(InvalidAssociationException.DOES_NOT_EXISTS); } return finalTarget; }
/** * Support to build node lists from category service API calls. * * @param childRefs Collection<ChildAssociationRef> * @return List of TemplateNode */ private List<TemplateNode> buildTemplateNodeList(Collection<ChildAssociationRef> childRefs) { List<TemplateNode> answer = new ArrayList<TemplateNode>(childRefs.size()); for (ChildAssociationRef ref : childRefs) { // create our Node representation from the NodeRef TemplateNode child = new TemplateNode(ref.getChildRef(), this.services, this.imageResolver); answer.add(child); } return answer; }
/** * Gets the primary parent association * * @param node the node to process * @return the primary parent association or null if this is a root node */ public static ChildAssociationRef getPrimaryParentAssoc(TransferManifestNormalNode node) { List<ChildAssociationRef> assocs = node.getParentAssocs(); for (ChildAssociationRef assoc : assocs) { if (assoc.isPrimary()) { return assoc; } } return null; }
/** * @see * org.alfresco.service.cmr.coci.CheckOutCheckInService#checkout(org.alfresco.service.cmr.repository.NodeRef) */ public NodeRef checkout(NodeRef nodeRef) { // Find the primary parent in order to determine where to put the copy ChildAssociationRef childAssocRef = this.nodeService.getPrimaryParent(nodeRef); // Checkout the working copy to the same destination return checkout( nodeRef, childAssocRef.getParentRef(), childAssocRef.getTypeQName(), childAssocRef.getQName()); }
/** * Create the specified home space if it does not exist, and return the ID * * @param locationId Parent location * @param spaceName Home space to create, can be null to simply return the parent * @param oldHomeFolderRef the previous home space, for the case where the the user is being * updated. It may not have changed. * @param error True to throw an error if the space already exists, else ignore and return * @return ID of the home space */ protected NodeRef createHomeSpace( String locationId, String spaceName, NodeRef oldHomeFolderRef, boolean error) { NodeRef homeSpaceNodeRef = null; if (spaceName != null && spaceName.length() != 0) { NodeRef parentRef = new NodeRef(Repository.getStoreRef(), locationId); // check for existence of home space with same name - return immediately // if it exists or throw an exception an give user chance to enter another name NodeRef childRef = this.getNodeService().getChildByName(parentRef, ContentModel.ASSOC_CONTAINS, spaceName); if (childRef != null) { if (childRef.equals(oldHomeFolderRef)) { return oldHomeFolderRef; } if (error) { throw new AlfrescoRuntimeException("A Home Space with the same name already exists."); } else { return childRef; } } // space does not exist already, create a new Space under it with // the specified name String qname = QName.createValidLocalName(spaceName); ChildAssociationRef assocRef = this.getNodeService() .createNode( parentRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, qname), ContentModel.TYPE_FOLDER); NodeRef nodeRef = assocRef.getChildRef(); // set the name property on the node this.getNodeService().setProperty(nodeRef, ContentModel.PROP_NAME, spaceName); if (logger.isDebugEnabled()) logger.debug("Created Home Space for with name: " + spaceName); // apply the uifacets aspect - icon, title and description props Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(3); uiFacetsProps.put(ApplicationModel.PROP_ICON, CreateSpaceWizard.DEFAULT_SPACE_ICON_NAME); uiFacetsProps.put(ContentModel.PROP_TITLE, spaceName); this.getNodeService().addAspect(nodeRef, ApplicationModel.ASPECT_UIFACETS, uiFacetsProps); setupHomeSpacePermissions(nodeRef); // return the ID of the created space homeSpaceNodeRef = nodeRef; } return homeSpaceNodeRef; }
/* * (non-Javadoc) * @see org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service.cmr.repository.NodeRef) */ public Serializable getValue(NodeRef nodeRef) { if (nodeRef.equals(getServiceRegistry().getCMISService().getDefaultRootNodeRef())) { return null; } ChildAssociationRef car = getServiceRegistry().getNodeService().getPrimaryParent(nodeRef); if ((car != null) && (car.getParentRef() != null)) { return car.getParentRef().toString(); } else { return null; } }
/** * Helper method to set audited information after method invocation and to determine if auditing * should take place based on the method return value. * * @param auditMode * @param auditInfo * @param mi * @param returnObject * @return - the audit mode. */ private AuditMode postInvocation( AuditMode auditMode, AuditState auditInfo, MethodInvocation mi, Object returnObject) { if (returnObject == null) { auditInfo.setReturnObject(null); } else if (returnObject instanceof Serializable) { auditInfo.setReturnObject((Serializable) returnObject); } else { auditInfo.setReturnObject(returnObject.toString()); } Auditable auditable = mi.getMethod().getAnnotation(Auditable.class); if (auditable.key() == Auditable.Key.RETURN) { if (returnObject != null) { if (returnObject instanceof NodeRef) { NodeRef key = (NodeRef) returnObject; auditInfo.setKeyStore(key.getStoreRef()); auditInfo.setKeyGUID(key.getId()); RecordOptions recordOptions = auditModel.getAuditRecordOptions(mi); if (recordOptions != null && recordOptions.getRecordPath() == TrueFalseUnset.TRUE) { auditInfo.setPath(getNodePath(key)); } } else if (returnObject instanceof StoreRef) { auditInfo.setKeyStore((StoreRef) returnObject); } else if (returnObject instanceof ChildAssociationRef) { ChildAssociationRef car = (ChildAssociationRef) returnObject; auditInfo.setKeyStore(car.getChildRef().getStoreRef()); auditInfo.setKeyGUID(car.getChildRef().getId()); RecordOptions recordOptions = auditModel.getAuditRecordOptions(mi); if (recordOptions != null && recordOptions.getRecordPath() == TrueFalseUnset.TRUE) { auditInfo.setPath(nodeService.getPath(car.getChildRef()).toString()); } } else { logger.warn( "Key argument is not a node, store or child assoc ref for return object on " + publicServiceIdentifier.getPublicServiceName(mi) + "." + mi.getMethod().getName() + " it is " + returnObject.getClass().getName()); } } } // If the user name is not set, try and set it after the method call. // This covers authentication when the user is only known after the call. if (auditInfo.getUserIdentifier() == null) { auditInfo.setUserIdentifier(AuthenticationUtil.getFullyAuthenticatedUser()); } return auditMode; }
/** * Retrieves the forum node the the given discussable * * @return Returns the <b>fm:forum</b> node or <tt>null</tt> */ private NodeRef getForum(NodeRef discussableNodeRef) { List<ChildAssociationRef> destChildren = nodeService.getChildAssocs( discussableNodeRef, ForumModel.ASSOC_DISCUSSION, RegexQNamePattern.MATCH_ALL); // Take the first one if (destChildren.size() == 0) { return null; } else { // We just take the first one ChildAssociationRef discussionAssoc = destChildren.get(0); return discussionAssoc.getChildRef(); } }
private List<TemplateNode> buildMixedNodeList(Collection<ChildAssociationRef> cars) { List<TemplateNode> nodes = new ArrayList<TemplateNode>(cars.size()); int i = 0; for (ChildAssociationRef car : cars) { QName type = services.getNodeService().getType(car.getChildRef()); if (services.getDictionaryService().isSubClass(type, ContentModel.TYPE_CATEGORY)) { nodes.add(new CategoryTemplateNode(car.getChildRef(), this.services, this.imageResolver)); } else { nodes.add(new TemplateNode(car.getChildRef(), this.services, this.imageResolver)); } } return nodes; }
/** * Force copy recursion after copying a rules folder * * @return Returns {@link ChildAssocRecurseAction#FORCE_RECURSE} for {@link * RuleModel#ASSOC_RULE_FOLDER} */ @Override public ChildAssocRecurseAction getChildAssociationRecurseAction( QName classQName, CopyDetails copyDetails, CopyChildAssociationDetails childAssocCopyDetails) { ChildAssociationRef childAssocRef = childAssocCopyDetails.getChildAssocRef(); if (childAssocRef.getTypeQName().equals(RuleModel.ASSOC_RULE_FOLDER)) { return ChildAssocRecurseAction.FORCE_RECURSE; } else { super.throwExceptionForUnexpectedBehaviour(copyDetails, childAssocCopyDetails.toString()); return null; // Never reached } }
/** * Actualitza el tamany de l'expedient. * * @param nodeRef * @param parentNodeRef */ private void updateExpedient(NodeService nodeService, NodeRef docNodeRef, NodeRef expNodeRef) { System.out.println( DateFormat.getInstance().format(new Date()) + " START: Recalcular tamany expedient."); int tamany = 0; List<ChildAssociationRef> children = nodeService.getChildAssocs(expNodeRef); for (ChildAssociationRef childAssoc : children) { NodeRef childNodeRef = childAssoc.getChildRef(); Serializable tamanySerial = nodeService.getProperty(childNodeRef, tamanyDocumentSimpleRM); if (tamanySerial != null && !"".equals(tamanySerial)) { tamany = tamany + (Integer.parseInt((String) tamanySerial)); } } nodeService.setProperty(expNodeRef, tamanyExpedientRM, String.valueOf(tamany)); Date now = new Date(); System.out.println( DateFormat.getInstance().format(now) + " Update tamany expedient: " + expNodeRef); System.out.println(DateFormat.getInstance().format(now) + " END: Recalcular tamany expedient."); }
/** * Actualitza el tamany del fons. * * @param nodeRef * @param parentNodeRef */ private void updateFons(NodeService nodeService, NodeRef serieNodeRef, NodeRef fonsNodeRef) { System.out.println( DateFormat.getInstance().format(new Date()) + " START: Recalcular tamany fons."); int tamany = 0; List<ChildAssociationRef> children = nodeService.getChildAssocs(fonsNodeRef); for (ChildAssociationRef childAssoc : children) { NodeRef childNodeRef = childAssoc.getChildRef(); Serializable tamanySerial = nodeService.getProperty(childNodeRef, tamanySerieRM); if (tamanySerial != null) { tamany = tamany + (Integer.parseInt((String) tamanySerial)); } } nodeService.setProperty(fonsNodeRef, tamanyFonsRM, String.valueOf(tamany)); Date now = new Date(); System.out.println( DateFormat.getInstance().format(now) + " Update tamany fons: " + fonsNodeRef); System.out.println(DateFormat.getInstance().format(now) + " END: Recalcular tamany fons."); }
@After public void deleteTestNodes() throws Exception { AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER); // Find the shared system container, and zap contents NodeRef container = ((RemoteCredentialsServiceImpl) PRIVATE_REMOTE_CREDENTIALS_SERVICE) .getSharedContainerNodeRef(false); if (container != null) { List<NodeRef> children = new ArrayList<NodeRef>(); for (ChildAssociationRef child : PUBLIC_NODE_SERVICE.getChildAssocs(container)) { children.add(child.getChildRef()); } performDeletionOfNodes(children); } // Zap the users, including any credentials stored for them deleteUser(TEST_USER_ONE); deleteUser(TEST_USER_TWO); deleteUser(TEST_USER_THREE); }
/** Ensure that the node has a <b>fm:forum</b> child node otherwise create one */ public void onAddAspect(NodeRef discussableNodeRef, QName aspectTypeQName) { String name = (String) this.nodeService.getProperty(discussableNodeRef, ContentModel.PROP_NAME); String forumName = I18NUtil.getMessage("discussion.discussion_for", new Object[] {name}); NodeRef forumNodeRef = getForum(discussableNodeRef); if (forumNodeRef == null) { Map<QName, Serializable> forumProps = new HashMap<QName, Serializable>(1); forumProps.put(ContentModel.PROP_NAME, forumName); ChildAssociationRef childRef = nodeService.createNode( discussableNodeRef, ForumModel.ASSOC_DISCUSSION, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion"), ForumModel.TYPE_FORUM, forumProps); forumNodeRef = childRef.getChildRef(); } else { // Just adjust the name nodeService.setProperty(forumNodeRef, ContentModel.PROP_NAME, forumName); } // apply the uifacets aspect Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(5); uiFacetsProps.put(ApplicationModel.PROP_ICON, "forum"); this.nodeService.addAspect(forumNodeRef, ApplicationModel.ASPECT_UIFACETS, uiFacetsProps); // Done if (logger.isDebugEnabled()) { logger.debug( "Created forum node for discussion: \n" + " Discussable Node: " + discussableNodeRef + "\n" + " Forum Node: " + forumNodeRef); } }
@Override public void unLink(String specific) throws AfException { if (isNew()) { throw new AfException("this object is new, you can not unlink it"); } NodeService nodeService = ServiceHelper.getNodeService(afSession); NodeRef parent = getSpecifiedNode(specific); if (parent == null || !(nodeService.exists(parent))) { return; } List<ChildAssociationRef> parents = nodeService.getParentAssocs(nodeRef); for (ChildAssociationRef ref : parents) { if (ref.getParentRef().getId().equals(parent.getId())) { if (!ref.isPrimary()) { // not primary,delete nodeService.removeChildAssociation(ref); return; } else { // primary, it's not a good coding.f**k it! String rootId = AFCHelper.getNodeRefByPath(afSession, "/").getId(); if (parents.size() <= 1) { if (rootId.equals(ref.getParentRef().getId())) { return; } else { moveTo("/", null); nodeService.removeChildAssociation(ref); return; } } else { // set the 2nd as the primary.moveTo for (ChildAssociationRef anotherP : parents) { if (!anotherP.equals(ref)) { String scndPId = anotherP.getParentRef().getId(); nodeService.removeChildAssociation(anotherP); moveTo(scndPId, null); nodeService.removeChildAssociation(ref); return; } } } } } } }
/** * {@inheritDoc} * * <p>This method is thread-safe and lazily creates the required references, if required. */ public ChildAssociationRef getChildAssocRef(QNameDAO qnameDAO) { boolean trashReference = false; // first check if it is available refReadLock.lock(); try { if (childAssocRef != null) { // double check that the parent and child node references match those of our reference if (childAssocRef.getParentRef() != parent.getNodeRef() || childAssocRef.getChildRef() != child.getNodeRef()) { trashReference = true; } else { // we are sure that the reference is correct return childAssocRef; } } } finally { refReadLock.unlock(); } // get write lock refWriteLock.lock(); try { // double check if (childAssocRef == null || trashReference) { if (typeQName == null) { typeQName = qnameDAO.getQName(this.typeQNameId).getSecond(); } if (qname == null) { String qnameNamespace = qnameDAO.getNamespace(qnameNamespaceId).getSecond(); qname = QName.createQName(qnameNamespace, qnameLocalName); } childAssocRef = new ChildAssociationRef( typeQName, parent.getNodeRef(), qname, child.getNodeRef(), this.isPrimary, index); } return childAssocRef; } finally { refWriteLock.unlock(); } }
/** * This method sets the node(s) to publish or unpublish on the supplied publishing details. If the * actionedUponNode is a folder then it will include all content nodes within that folder. * * @param actionedUponNodeRef * @param unpublish * @param details */ private List<NodeRef> setNodes( NodeRef actionedUponNodeRef, boolean unpublish, PublishingDetails details) { List<NodeRef> nodes = new ArrayList<NodeRef>(); QName nodeType = nodeService.getType(actionedUponNodeRef); if (dictionaryService.isSubClass(nodeType, ContentModel.TYPE_FOLDER)) { List<ChildAssociationRef> children = nodeService.getChildAssocs(actionedUponNodeRef); for (ChildAssociationRef childRef : children) { NodeRef child = childRef.getChildRef(); if (dictionaryService.isSubClass(nodeService.getType(child), ContentModel.TYPE_CONTENT)) { nodes.add(child); } } } else { nodes.add(actionedUponNodeRef); } if (unpublish) { details.addNodesToUnpublish(nodes); } else { details.addNodesToPublish(nodes); } return nodes; }
public NodeRef createDownloadNode(boolean recursive) { NodeRef downloadsContainer = getOrCreateDowloadContainer(); Map<QName, Serializable> downloadProperties = new HashMap<QName, Serializable>(); downloadProperties.put(DownloadModel.PROP_RECURSIVE, recursive); ChildAssociationRef newChildAssoc = nodeService.createNode( downloadsContainer, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, DownloadModel.TYPE_DOWNLOAD, downloadProperties); final NodeRef downloadNodeRef = newChildAssoc.getChildRef(); if (log.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("Created Download. ").append("', Download-NodeRef="); log.debug(msg.toString()); } return downloadNodeRef; }
protected List<NodeRef> getNodes( StoreRef storeRef, RepositoryLocation repositoryLocation, QName nodeType) { List<NodeRef> nodeRefs = new ArrayList<NodeRef>(); NodeRef rootNodeRef = nodeService.getRootNode(storeRef); if (nodeService.exists(rootNodeRef) == false) { // Tenant is deleted. But cache refresh was called to inform another cluster nodes // Should be reworked when MNT-11638 will be implemented return nodeRefs; } if (repositoryLocation instanceof DynamicCreateRepositoryLocation) { ((DynamicCreateRepositoryLocation) repositoryLocation).checkAndCreate(rootNodeRef); } String[] pathElements = repositoryLocation.getPathElements(); NodeRef folderNodeRef = rootNodeRef; if (pathElements.length > 0) { folderNodeRef = resolveQNamePath(rootNodeRef, pathElements); } if (folderNodeRef != null) { Set<QName> types = new HashSet<QName>(1); types.add(nodeType); List<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(folderNodeRef, types); if (childAssocRefs.size() > 0) { nodeRefs = new ArrayList<NodeRef>(childAssocRefs.size()); for (ChildAssociationRef childAssocRef : childAssocRefs) { nodeRefs.add(childAssocRef.getChildRef()); } } } return nodeRefs; }
@Override public void onCreateNode(ChildAssociationRef childAssociationRef) { NodeRef nodeRef = childAssociationRef.getChildRef(); // Bind the listener to the transaction AlfrescoTransactionSupport.bindListener(transactionListener); // Get the set of nodes written @SuppressWarnings("unchecked") Set<NodeRef> updatedNodes = (Set<NodeRef>) AlfrescoTransactionSupport.getResource(KEY_UPDATED_NODES); if (updatedNodes == null) { updatedNodes = new HashSet<NodeRef>(5); AlfrescoTransactionSupport.bindResource(KEY_UPDATED_NODES, updatedNodes); } updatedNodes.add(nodeRef); }
/** Test when the aspect is not set when check-in is performed */ public void testVersionAspectNotSetOnCheckIn() { // Create a bag of props Map<QName, Serializable> bagOfProps = createTypePropertyBag(); bagOfProps.put( ContentModel.PROP_CONTENT, new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, "UTF-8")); // Create a new node ChildAssociationRef childAssocRef = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("test"), ContentModel.TYPE_CONTENT, bagOfProps); NodeRef noVersionNodeRef = childAssocRef.getChildRef(); // Check out and check in NodeRef workingCopy = cociService.checkout(noVersionNodeRef); cociService.checkin(workingCopy, new HashMap<String, Serializable>()); // Check that the origional node has no version history dispite sending verion props assertNull(this.versionService.getVersionHistory(noVersionNodeRef)); }
/* (non-Javadoc) * @see org.alfresco.repo.tenant.TenantService#getBaseName(org.alfresco.service.cmr.repository.ChildAssociationRef) */ public ChildAssociationRef getBaseName(ChildAssociationRef childAssocRef) { if (childAssocRef == null) { return null; } return new ChildAssociationRef( childAssocRef.getTypeQName(), getBaseName(childAssocRef.getParentRef()), childAssocRef.getQName(), getBaseName(childAssocRef.getChildRef()), childAssocRef.isPrimary(), childAssocRef.getNthSibling()); }
/** {@inheritDoc} */ @Override public void onCreateNode(ChildAssociationRef childAssocRef) { this.auditComponent.recordAuditValues( CREATE_RATING_ROOT_PATH, Collections.<String, Serializable>singletonMap(KEY_NODE_REF, childAssocRef.getChildRef())); }
/** * Write exception transfer report * * @return NodeRef the node ref of the new transfer report */ public NodeRef createTransferReport( Exception e, TransferTarget target, TransferDefinition definition, List<TransferEvent> events, File snapshotFile) { Map<QName, Serializable> properties = new HashMap<QName, Serializable>(); SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssSSSZ"); String timeNow = format.format(new Date()); String title = "Transfer report, error, " + timeNow; String description = "Transfer error report"; String name = "Transfer error report, " + timeNow; properties.put(ContentModel.PROP_NAME, name); properties.put(ContentModel.PROP_TITLE, title); properties.put(ContentModel.PROP_DESCRIPTION, description); ChildAssociationRef ref = nodeService.createNode( target.getNodeRef(), ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name), TransferModel.TYPE_TRANSFER_REPORT, properties); ContentWriter writer = contentService.getWriter(ref.getChildRef(), ContentModel.PROP_CONTENT, true); writer.setLocale(Locale.getDefault()); writer.setMimetype(MimetypeMap.MIMETYPE_XML); writer.setEncoding(DEFAULT_ENCODING); // XMLTransferReportWriter reportWriter = new XMLTransferReportWriter(); BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(writer.getContentOutputStream())); try { reportWriter.startTransferReport(DEFAULT_ENCODING, bufferedWriter); // Header reportWriter.writeTarget(target); reportWriter.writeDefinition(definition); reportWriter.writeException(e); // Detail reportWriter.writeTransferEvents(events); reportWriter.endTransferReport(); return ref.getChildRef(); } catch (SAXException se) { return null; } finally { try { bufferedWriter.close(); } catch (IOException error) { error.printStackTrace(); } } }
/** * Create a new transfer report of success * * @return NodeRef the node ref of the new transfer report */ public NodeRef createTransferReport( Transfer transfer, TransferTarget target, TransferDefinition definition, List<TransferEvent> events, File snapshotFile) { Map<QName, Serializable> properties = new HashMap<QName, Serializable>(); SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssSSSZ"); String timeNow = format.format(new Date()); String title = "Transfer report, " + timeNow + "success"; String description = "Transfer report success targetName : " + target.getName(); String name = "Transfer report, " + timeNow; properties.put(ContentModel.PROP_NAME, name); properties.put(ContentModel.PROP_TITLE, title); properties.put(ContentModel.PROP_DESCRIPTION, description); ChildAssociationRef ref = nodeService.createNode( target.getNodeRef(), ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name), TransferModel.TYPE_TRANSFER_REPORT, properties); ContentWriter writer = contentService.getWriter(ref.getChildRef(), ContentModel.PROP_CONTENT, true); writer.setLocale(Locale.getDefault()); writer.setMimetype(MimetypeMap.MIMETYPE_XML); writer.setEncoding(DEFAULT_ENCODING); // final XMLTransferReportWriter reportWriter = new XMLTransferReportWriter(); BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(writer.getContentOutputStream())); try { reportWriter.startTransferReport(DEFAULT_ENCODING, bufferedWriter); // Header reportWriter.writeTarget(target); reportWriter.writeDefinition(definition); /** Write the node summary details to the transfer report */ TransferManifestProcessor processor = new TransferManifestProcessor() { public void processTransferManifestNode(TransferManifestNormalNode node) { try { reportWriter.writeNodeSummary(node); } catch (SAXException error) { error.printStackTrace(); } } public void processTransferManifestNode(TransferManifestDeletedNode node) { try { reportWriter.writeNodeSummary(node); } catch (SAXException error) { error.printStackTrace(); } } public void processTransferManifiestHeader(TransferManifestHeader header) { /* NO-OP */ } public void startTransferManifest() { /* NO-OP */ } public void endTransferManifest() { /* NO-OP */ } }; /** Step 3: wire up the manifest reader to a manifest processor */ SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); SAXParser parser; parser = saxParserFactory.newSAXParser(); XMLTransferManifestReader reader = new XMLTransferManifestReader(processor); /** Step 4: start the magic Give the manifest file to the manifest reader */ try { parser.parse(snapshotFile, reader); } catch (IOException error) { // TODO temp code error.printStackTrace(); return null; } // Detail Events reportWriter.writeTransferEvents(events); reportWriter.endTransferReport(); return ref.getChildRef(); } catch (SAXException se) { // TODO Temp code return null; } catch (ParserConfigurationException error) { // TODO temp code error.printStackTrace(); return null; } finally { try { bufferedWriter.close(); } catch (IOException error) { error.printStackTrace(); } } }
/** * Set auditable information and determine if auditing is required before method invocation. This * would normally be based on the method arguments. * * @param auditMode * @param auditInfo * @param mi * @return - the audit mode. */ private AuditMode beforeInvocation( AuditMode auditMode, AuditState auditInfo, MethodInvocation mi) { AuditMode effectiveAuditMode = auditModel.beforeExecution(auditMode, mi); if (auditMode != AuditMode.NONE) { String methodName = mi.getMethod().getName(); String serviceName = publicServiceIdentifier.getPublicServiceName(mi); auditInfo.setAuditApplication(SYSTEM_APPLICATION); auditInfo.setAuditConfiguration(auditConfiguration); auditInfo.setAuditMethod(methodName); auditInfo.setAuditService(serviceName); auditInfo.setClientAddress(null); auditInfo.setDate(new Date()); auditInfo.setFail(false); auditInfo.setFiltered(false); auditInfo.setHostAddress(auditHost); auditInfo.setPath(null); Auditable auditable = mi.getMethod().getAnnotation(Auditable.class); Object key = null; switch (auditable.key()) { case ARG_0: checkArgLength(mi, methodName, serviceName, 0); key = mi.getArguments()[0]; break; case ARG_1: checkArgLength(mi, methodName, serviceName, 1); key = mi.getArguments()[1]; break; case ARG_2: checkArgLength(mi, methodName, serviceName, 2); key = mi.getArguments()[2]; break; case ARG_3: checkArgLength(mi, methodName, serviceName, 3); key = mi.getArguments()[3]; break; case ARG_4: checkArgLength(mi, methodName, serviceName, 4); key = mi.getArguments()[4]; break; case ARG_5: checkArgLength(mi, methodName, serviceName, 5); key = mi.getArguments()[5]; break; case ARG_6: checkArgLength(mi, methodName, serviceName, 6); key = mi.getArguments()[6]; break; case ARG_7: checkArgLength(mi, methodName, serviceName, 7); key = mi.getArguments()[7]; break; case ARG_8: checkArgLength(mi, methodName, serviceName, 8); key = mi.getArguments()[8]; break; case ARG_9: checkArgLength(mi, methodName, serviceName, 9); key = mi.getArguments()[9]; break; case NO_KEY: default: break; } if (key != null) { RecordOptions recordOptions = auditModel.getAuditRecordOptions(mi); if (key instanceof NodeRef) { auditInfo.setKeyStore(((NodeRef) key).getStoreRef()); auditInfo.setKeyGUID(((NodeRef) key).getId()); if (recordOptions != null && recordOptions.getRecordPath() == TrueFalseUnset.TRUE) { auditInfo.setPath(getNodePath((NodeRef) key)); } } else if (key instanceof StoreRef) { auditInfo.setKeyStore((StoreRef) key); } else if (key instanceof ChildAssociationRef) { ChildAssociationRef car = (ChildAssociationRef) key; auditInfo.setKeyStore(car.getParentRef().getStoreRef()); auditInfo.setKeyGUID(car.getParentRef().getId()); if (recordOptions != null && recordOptions.getRecordPath() == TrueFalseUnset.TRUE) { auditInfo.setPath(getNodePath(car.getParentRef())); } } else if (key instanceof SearchParameters) { SearchParameters sp = (SearchParameters) key; if (sp.getStores().size() > 0) { auditInfo.setKeyStore(sp.getStores().get(0)); } } else { logger.warn( "Key argument is not a node, store or child assoc reference or search parameters on " + serviceName + "." + methodName + " it is " + key.getClass().getName()); } } auditInfo.setKeyPropertiesAfter(null); auditInfo.setKeyPropertiesBefore(null); auditInfo.setMessage(null); if (mi.getArguments() != null) { Serializable[] serArgs = new Serializable[mi.getArguments().length]; for (int i = 0; i < mi.getArguments().length; i++) { if ((auditable.recordable() == null) || (auditable.recordable().length <= i) || auditable.recordable()[i]) { if (mi.getArguments()[i] == null) { serArgs[i] = null; } else if (mi.getArguments()[i] instanceof Serializable) { serArgs[i] = (Serializable) mi.getArguments()[i]; } else { serArgs[i] = mi.getArguments()[i].toString(); } } else { serArgs[i] = "********"; } } auditInfo.setMethodArguments(serArgs); } auditInfo.setReturnObject(null); auditInfo.setSessionId(null); auditInfo.setThrowable(null); auditInfo.setTxId(AlfrescoTransactionSupport.getTransactionId()); auditInfo.setUserIdentifier(AuthenticationUtil.getFullyAuthenticatedUser()); } return effectiveAuditMode; }