Java Code Examples for org.alfresco.model.ContentModel

The following examples show how to use org.alfresco.model.ContentModel. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Checks that the {@link ContentModel#ASPECT_REFERENCEABLE referencable} properties
 * are present
 */
@Test
public void testGetReferencableProperties() throws Exception
{
    // check individual property retrieval
    Serializable wsProtocol = nodeService.getProperty(rootNodeRef, ContentModel.PROP_STORE_PROTOCOL);
    Serializable wsIdentifier = nodeService.getProperty(rootNodeRef, ContentModel.PROP_STORE_IDENTIFIER);
    Serializable nodeUuid = nodeService.getProperty(rootNodeRef, ContentModel.PROP_NODE_UUID);
    Serializable nodeDbId = nodeService.getProperty(rootNodeRef, ContentModel.PROP_NODE_DBID);
    
    assertNotNull("Workspace Protocol property not present", wsProtocol);
    assertNotNull("Workspace Identifier property not present", wsIdentifier);
    assertNotNull("Node UUID property not present", nodeUuid);
    assertNotNull("Node DB ID property not present", nodeDbId);
    
    assertEquals("Workspace Protocol property incorrect", rootNodeRef.getStoreRef().getProtocol(), wsProtocol);
    assertEquals("Workspace Identifier property incorrect", rootNodeRef.getStoreRef().getIdentifier(), wsIdentifier);
    assertEquals("Node UUID property incorrect", rootNodeRef.getId(), nodeUuid);
    
    // check mass property retrieval
    Map<QName, Serializable> properties = nodeService.getProperties(rootNodeRef);
    assertTrue("Workspace Protocol property not present in map", properties.containsKey(ContentModel.PROP_STORE_PROTOCOL));
    assertTrue("Workspace Identifier property not present in map", properties.containsKey(ContentModel.PROP_STORE_IDENTIFIER));
    assertTrue("Node UUID property not present in map", properties.containsKey(ContentModel.PROP_NODE_UUID));
    assertTrue("Node DB ID property not present in map", properties.containsKey(ContentModel.PROP_NODE_DBID));
}
 
Example 2
private void createUser(String userName)
{
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    if (this.authenticationService.authenticationExists(userName) == false)
    {
        this.authenticationService.createAuthentication(userName, "password".toCharArray());

        PropertyMap map = new PropertyMap(5);
        map.put(ContentModel.PROP_USERNAME, userName);
        map.put(ContentModel.PROP_FIRSTNAME, "firstName");
        map.put(ContentModel.PROP_LASTNAME, "lastName");
        map.put(ContentModel.PROP_EMAIL, "[email protected]");
        map.put(ContentModel.PROP_JOBTITLE, "jobTitle");

        this.personService.createPerson(map);
        this.createdPeople.add(userName);
    }
}
 
Example 3
/**
 * Initialise method
 */
public void init()
{
    // Prevent the ratebale aspect from being copied
    bindNoCopyBehaviour(ContentModel.ASPECT_RATEABLE);

    // Prevent the roll up aspects from being copied
    for (RatingScheme ratingScheme : ratingSchemeRegistry.getRatingSchemes().values())
    {
        if (ratingScheme.getPropertyRollups() != null && ratingScheme.getPropertyRollups().size() > 0) 
        {
            QName rollupAspectName = ratingNamingConventions.getRollupAspectNameFor(ratingScheme);
            bindNoCopyBehaviour(rollupAspectName);
        }
    }
}
 
Example 4
private void createUser(String userName)
{
    if (this.authenticationService.authenticationExists(userName) == false)
    {
        this.authenticationService.createAuthentication(userName, "PWD".toCharArray());
        
        PropertyMap ppOne = new PropertyMap(4);
        ppOne.put(ContentModel.PROP_USERNAME, userName);
        ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
        ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
        ppOne.put(ContentModel.PROP_EMAIL, "[email protected]");
        ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
        
        this.personService.createPerson(ppOne);
    }        
}
 
Example 5
/**
 * @see org.alfresco.repo.action.evaluator.ActionConditionEvaluatorAbstractBase#evaluateImpl(org.alfresco.service.cmr.action.ActionCondition, org.alfresco.service.cmr.repository.NodeRef)
 */
public boolean evaluateImpl(ActionCondition ruleCondition, NodeRef actionedUponNodeRef)
{
    boolean result = false;
    
    if (this.nodeService.exists(actionedUponNodeRef) == true && 
        this.nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
    {
        VersionHistory versionHistory = this.versionService.getVersionHistory(actionedUponNodeRef);
        if (versionHistory != null && versionHistory.getAllVersions().size() != 0)
        {
            result = true;
        }
    }
    
    return result;
}
 
Example 6
private void createUser(String userName)
{
    if (this.authenticationService.authenticationExists(userName) == false)
    {
        this.authenticationService.createAuthentication(userName, "password".toCharArray());
        
        PropertyMap personProps = new PropertyMap();
        personProps.put(ContentModel.PROP_USERNAME, userName);
        personProps.put(ContentModel.PROP_FIRSTNAME, "myFirstName");
        personProps.put(ContentModel.PROP_LASTNAME, "myLastName");
        personProps.put(ContentModel.PROP_EMAIL, "[email protected]");
        personProps.put(ContentModel.PROP_JOBTITLE, "myJobTitle");
        personProps.put(ContentModel.PROP_JOBTITLE, "myOrganisation");
        
        this.personService.createPerson(personProps);
        
        this.createdPeople.add(userName);
    }        
}
 
Example 7
@SuppressWarnings("unused")
@Test
public void testCheckHidden() throws Exception
{
    String nodeName = GUID.generate();

    interceptor.setEnabled(false);

    try
    {
        // Create some nodes that should be hidden but aren't
        NodeRef node = fileFolderService.create(topNodeRef, nodeName, ContentModel.TYPE_FOLDER).getNodeRef();
        NodeRef node11 = fileFolderService.create(node, nodeName + ".11", ContentModel.TYPE_FOLDER).getNodeRef();
        NodeRef node12 = fileFolderService.create(node, ".12", ContentModel.TYPE_CONTENT).getNodeRef();
        NodeRef node21 = fileFolderService.create(node11, nodeName + ".21", ContentModel.TYPE_FOLDER).getNodeRef();
        NodeRef node22 = fileFolderService.create(node11, nodeName + ".22", ContentModel.TYPE_CONTENT).getNodeRef();
        NodeRef node31 = fileFolderService.create(node21, ".31", ContentModel.TYPE_FOLDER).getNodeRef();
        NodeRef node41 = fileFolderService.create(node31, nodeName + ".41", ContentModel.TYPE_CONTENT).getNodeRef();

        txn.commit();
    }
    finally
    {
        interceptor.setEnabled(true);
    }
}
 
Example 8
public boolean isValidCmisRelationshipEndPoint(QName typeQName)
{
    if(dictionaryService.getClass(typeQName).isAspect())
    {
        return true;
    }
    
    if (typeQName.equals(FOLDER_QNAME))
    {
        return true;
    }

    
    if (typeQName.equals(DOCUMENT_QNAME))
    {
        return true;
    }

    if (dictionaryService.isSubClass(typeQName, ContentModel.TYPE_BASE))
    {
        return true;
    }
    return false;
}
 
Example 9
/**
 * Test getWriter
 */
@Test
public void testGetWriter()
{
    // Create a new versionable node
    NodeRef versionableNode = createNewVersionableNode();
    
    // Create a new version
    Version version = createVersion(versionableNode, this.versionProperties);
    
    // Get writer is not supported by the version content service
    try
    {
        ContentWriter contentWriter = this.contentService.getWriter(
                version.getFrozenStateNodeRef(),
                ContentModel.PROP_CONTENT,
                true);
        contentWriter.putContent("bobbins");
        fail("This operation is not supported.");
    }
    catch (Exception exception)
    {
        // An exception should be raised
    }
}
 
Example 10
private void createUser(String userName, String role)
{
    // if user with given user name doesn't already exist then create user
    if (this.authenticationService.authenticationExists(userName) == false)
    {
        // create user
        this.authenticationService.createAuthentication(userName, "password".toCharArray());
        
        // create person properties
        PropertyMap personProps = new PropertyMap();
        personProps.put(ContentModel.PROP_USERNAME, userName);
        personProps.put(ContentModel.PROP_FIRSTNAME, "FirstName123");
        personProps.put(ContentModel.PROP_LASTNAME, "LastName123");
        personProps.put(ContentModel.PROP_EMAIL, "[email protected]");
        personProps.put(ContentModel.PROP_JOBTITLE, "JobTitle123");
        personProps.put(ContentModel.PROP_JOBTITLE, "Organisation123");
        
        // create person node for user
        this.personService.createPerson(personProps);
    }
    
    // add the user as a member with the given role
    this.siteService.setMembership(SITE_SHORT_NAME_CALENDAR, userName, role);
}
 
Example 11
public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isArchivedNode)
{
    // add the child to the list
    deletedNodeRefs.add(childAssocRef.getChildRef());
    
    if(onDeleteCreateChild)
    {
        System.out.println("on delete node - add sibling.");
        // now perform some nasties on the node's parent, i.e. add a new child
        NodeRef parentRef = childAssocRef.getParentRef();
        NodeRef childRef = childAssocRef.getChildRef();
        ChildAssociationRef assocRef = nodeService.createNode(
            parentRef,
            ASSOC_TYPE_QNAME_TEST_CHILDREN,
            QName.createQName("post-delete new child"),
            ContentModel.TYPE_CONTAINER);
    }
}
 
Example 12
protected final MetadataLoader.Metadata loadMetadata(ImportableItem.ContentAndMetadata contentAndMetadata)
{
    MetadataLoader.Metadata result = new MetadataLoader.Metadata();
    
    // Load "standard" metadata from the filesystem
    if (contentAndMetadata != null && contentAndMetadata.contentFileExists())
    {
        final String filename = contentAndMetadata.getContentFile().getFileName().toString().trim().replaceFirst(DirectoryAnalyser.VERSION_SUFFIX_REGEX, "");  // Strip off the version suffix (if any)
        final Date   modified = contentAndMetadata.getContentFileModifiedDate();
        final Date   created  = contentAndMetadata.getContentFileCreatedDate();

        result.setType(ImportableItem.FileType.FILE.equals(contentAndMetadata.getContentFileType()) ? ContentModel.TYPE_CONTENT : ContentModel.TYPE_FOLDER);
        result.addProperty(ContentModel.PROP_NAME,     filename);
        result.addProperty(ContentModel.PROP_TITLE,    filename);
        result.addProperty(ContentModel.PROP_CREATED,  created);
        result.addProperty(ContentModel.PROP_MODIFIED, modified);
    }

    if (metadataLoader != null)
    {
        metadataLoader.loadMetadata(contentAndMetadata, result);
    }

    return(result);
}
 
Example 13
public void beforeDeleteNode(NodeRef nodeRef)
{
    // Get the node's properties
    nodeService.getProperties(nodeRef);
    // add the child to the list
    beforeDeleteNodeRefs.add(nodeRef);
    
    if(beforeDeleteCreateChild)
    {
        System.out.println("before delete node - add child.");
        // add a new child to the child, i.e. just before it is deleted
        ChildAssociationRef assocRef = nodeService.createNode(
            nodeRef,
            ASSOC_TYPE_QNAME_TEST_CHILDREN,
            QName.createQName("pre-delete new child"),
            ContentModel.TYPE_CONTAINER);
        // set some child node properties
        nodeService.setProperty(nodeRef, PROP_QNAME_BOOLEAN_VALUE, "true");
        // add an aspect to the child
        nodeService.addAspect(nodeRef, ASPECT_QNAME_TEST_TITLED, null);
    }

}
 
Example 14
@Test
public void testAR807() 
{
	QName prop = QName.createQName("http://www.alfresco.org/test/versionstorebasetest/1.0", "intProp");
	
    ChildAssociationRef childAssociation = 
    	nodeService.createNode(this.rootNodeRef, 
                				 ContentModel.ASSOC_CHILDREN, 
                				 QName.createQName("http://www.alfresco.org/test/versionstorebasetest/1.0", "integerTest"), 
                				 TEST_TYPE_QNAME);
    NodeRef newNode = childAssociation.getChildRef();
    nodeService.setProperty(newNode, prop, 1);

    Object editionCode = nodeService.getProperty(newNode, prop);
    assertEquals(editionCode.getClass(), Integer.class);

    Map<String, Serializable> versionProps = new HashMap<String, Serializable>(1);
    versionProps.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
    Version version = versionService.createVersion(newNode, versionProps);

    NodeRef versionNodeRef = version.getFrozenStateNodeRef();
    assertNotNull(versionNodeRef);
    
    Object editionCodeArchive = nodeService.getProperty(versionNodeRef, prop);
    assertEquals(editionCodeArchive.getClass(), Integer.class);
}
 
Example 15
/**
 * Get the type of child association that should be created.
 * 
 * @param parentNodeRef the parent
 * @return Returns the appropriate child association type qualified name for the type of the
 *      parent.  Null will be returned if it can't be determined.
 */
private QName getAssocTypeQName(NodeRef parentNodeRef)
{
    // check the parent node's type to determine which association to use
    QName parentNodeTypeQName = nodeService.getType(parentNodeRef);
    QName assocTypeQName = null;
    if (dictionaryService.isSubClass(parentNodeTypeQName, ContentModel.TYPE_CONTAINER))
    {
        // it may be a root node or something similar
        assocTypeQName = ContentModel.ASSOC_CHILDREN;
    }
    else if (dictionaryService.isSubClass(parentNodeTypeQName, ContentModel.TYPE_FOLDER))
    {
        // more like a directory
        assocTypeQName = ContentModel.ASSOC_CONTAINS;
    }
    return assocTypeQName;
}
 
Example 16
/**
 * Get all transfer targets in the specified group
 */
public Set<TransferTarget> getTransferTargets(String groupName)
{
    NodeRef home = getTransferHome();
    
    // get group with assoc groupName
    NodeRef groupNode = nodeService.getChildByName(home, ContentModel.ASSOC_CONTAINS, groupName);
    
    if(groupNode == null)
    {
        // No transfer group.
        throw new TransferException(MSG_NO_GROUP, new Object[]{groupName});
    }
    
    return getTransferTargets(groupNode);
}
 
Example 17
public void onCreateNode(ChildAssociationRef childAssocRef)
{
    NodeRef nodeRef = childAssocRef.getChildRef();
    
    if (logger.isTraceEnabled())
    {
        logger.trace("onCreateNode: nodeRef="+nodeRef+ " ["+AlfrescoTransactionSupport.getTransactionId()+"]");
    }
    
    if (nodeService.getType(nodeRef).equals(ContentModel.TYPE_DICTIONARY_MODEL))
    {
        Boolean value = (Boolean)nodeService.getProperty(nodeRef, ContentModel.PROP_MODEL_ACTIVE);
        if ((value != null) && (value == true))
        {
            queueModel(nodeRef);
        }
    }
}
 
Example 18
private boolean setLocaleProp(NodeRef node, Locale locale) throws Exception
{
    Map<QName, Serializable> props = nodeService.getProperties(node);
    props.put(ContentModel.PROP_LOCALE, locale);
    
    boolean exceptionCatched = false;
    
    try 
    {
        nodeService.setProperties(node, props);
        
    } 
    catch (IllegalArgumentException ignore) 
    {
        exceptionCatched = true;
    }
    catch(Exception ex)
    {
        throw new Exception(ex);
    }

    
    return exceptionCatched;
}
 
Example 19
/**
 * Publish new user event
 * 
 * @param eventType String
 * @param properties Map<QName, Serializable>
 */
private void publishEvent(String eventType,  Map<QName, Serializable> properties)
{
	if(properties == null)	return;
	
 	final String managedUsername  = (String)properties.get(ContentModel.PROP_USERNAME);
    final String managedFirstname = (String)properties.get(ContentModel.PROP_FIRSTNAME);
    final String managedLastname  = (String)properties.get(ContentModel.PROP_LASTNAME);
    final String eventTType 	  = eventType;
    
    eventPublisher.publishEvent(new EventPreparator(){
        @Override
        public Event prepareEvent(String user, String networkId, String transactionId)
        {         
        	return new UserManagementEvent(eventTType , transactionId, networkId,new Date().getTime(), 
        			user, managedUsername,managedFirstname,managedLastname);
        }
    });
}
 
Example 20
public void saveRenditionDefinition(RenditionDefinition renderingAction)
{
    NodeRef actionNodeRef = findOrCreateActionNode(renderingAction);
    
    // ALF-9166 describes a problem whereby versionable saved rendition definition nodes cause problems on upgrade.
    // This appears to be due to a rule defined on Company Home. The behaviour suppression below is a workaround for that issue.
    try
    {
        behaviourFilter.disableBehaviour(actionNodeRef, ContentModel.ASPECT_VERSIONABLE);
        
        // TODO Serialize using JSON content instead.
        // The current serialization mechanism creates a complex content model
        // structure which is verbose and a JSON-based approach using a simplified
        // content model perhaps could offer performance improvements.
        runtimeActionService.saveActionImpl(actionNodeRef, renderingAction);
    }
    finally
    {
        behaviourFilter.enableBehaviour(actionNodeRef, ContentModel.ASPECT_VERSIONABLE);
    }
}
 
Example 21
private void addMessageResource(NodeRef rootNodeRef, String name, InputStream resourceStream) throws Exception
{       
    Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
    contentProps.put(ContentModel.PROP_NAME, name);
    
    ChildAssociationRef association = nodeService.createNode(rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
            ContentModel.TYPE_CONTENT,
            contentProps);
    
    NodeRef content = association.getChildRef();
    
    ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);

    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    writer.setEncoding("UTF-8");

    writer.putContent(resourceStream);
    resourceStream.close();
}
 
Example 22
@Test
public void testCheckInLockableAspectDoesntCopies_ALF16194()
{
    // Check-out nodeRef
    NodeRef workingCopy = this.cociService.checkout(
            this.nodeRef, 
            this.rootNodeRef, 
            ContentModel.ASSOC_CHILDREN, 
            QName.createQName("workingCopy"));
    assertNotNull(workingCopy);
    
    // Check-in 
    Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
    versionProperties.put(Version.PROP_DESCRIPTION, "This is a test version");      
    cociService.checkin(workingCopy, versionProperties);
    
    if(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE))
    {
        fail("Lockable aspect should not be copied from the working copy to the original document");
    }
}
 
Example 23
@Override
public void applyRating(NodeRef nodeRef, Object rating)
{
	try
	{
		Float ratingServiceRating = getRatingServiceRating(rating);
		ratingService.applyRating(nodeRef, ratingServiceRating, getRatingServiceName());

		QName nodeType = nodeService.getType(nodeRef);
           boolean isContainer = dictionaryService.isSubClass(nodeType, ContentModel.TYPE_FOLDER) &&
                   !dictionaryService.isSubClass(nodeType, ContentModel.TYPE_SYSTEM_FOLDER);
		postActivity(nodeRef, isContainer ? ActivityType.FOLDER_LIKED : ActivityType.FILE_LIKED);
	}
	catch(RatingServiceException e)
	{
		throw new InvalidArgumentException(e.getMessage());
	}
}
 
Example 24
private NodeRef makeRenditionNode(NodeRef parent, String title, String name, String mimetype)
  {
      Map<QName, Serializable> props = new HashMap<QName, Serializable>();
      props.put(ContentModel.PROP_NAME, name);
      props.put(ContentModel.PROP_TITLE, title);
      QName assocQName = QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, name);
      ChildAssociationRef assoc = nodeService.createNode(parent, RenditionModel.ASSOC_RENDITION,
          assocQName, ContentModel.TYPE_THUMBNAIL, props);
      NodeRef childRef = assoc.getChildRef();

      if (!nodeService.hasAspect(parent, RenditionModel.ASPECT_RENDITIONED))
      {
          nodeService.addAspect(parent, RenditionModel.ASPECT_RENDITIONED, null);
      }

      ContentWriter writer = contentService.getWriter(childRef, ContentModel.PROP_CONTENT, true);
      writer.setMimetype(mimetype);
      writer.setEncoding("UTF-8");
writer.putContent("Dummy "+name+" content");

      return childRef;
  }
 
Example 25
@Test
public void testFilingPath_specialCharacters() throws Exception
{
    NodeRef vfNodeRef = createVirtualizedFolder(testRootFolder.getNodeRef(),
                                                "Template 6 With Spaces",
                                                TEST_TEMPLATE_5_JSON_SYS_PATH);

    NodeRef sfpNodeRef = nodeService.getChildByName(vfNodeRef,
                                                    ContentModel.ASSOC_CONTAINS,
                                                    "SpecialFilingPath4");

    Reference sfpReference = Reference.fromNodeRef(sfpNodeRef);
    ApplyTemplateMethod applyTemplateMethod = new ApplyTemplateMethod(environment);

    VirtualFolderDefinition structure = sfpReference.execute(applyTemplateMethod);

    FilingRule filingRule = structure.getFilingRule();
    assertTrue(filingRule instanceof TemplateFilingRule);

    NodeRef fn = filingRule.filingNodeRefFor(new FilingParameters(sfpReference));
    assertNotNull(fn);
}
 
Example 26
/**
 * Test execution
 */
@Test
public void testExecution()
{
    // Execute the action
    ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
    action.setParameterValue(SetPropertyValueActionExecuter.PARAM_PROPERTY, ContentModel.PROP_NAME);
    action.setParameterValue(SetPropertyValueActionExecuter.PARAM_VALUE, TEST_VALUE);
    this.executer.execute(action, this.nodeRef);
    
    // Check that the property value has been set
    assertEquals(TEST_VALUE, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_NAME));
    
    // Check what happens when a bad property name is set
    action.setParameterValue(SetPropertyValueActionExecuter.PARAM_PROPERTY, QName.createQName("{test}badProperty"));
    
    try
    {
        this.executer.execute(action, this.nodeRef);
        fail("We would expect and exception to be thrown since the property name is invalid.");
    }
    catch (Throwable exception)
    {
        // Good .. we where expecting this
    }
}
 
Example 27
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    transactionService = (TransactionService) ctx.getBean("TransactionService");
    nodeService = (NodeService) ctx.getBean("NodeService");
    contentService = (ContentService) ctx.getBean(ServiceRegistry.CONTENT_SERVICE.getLocalName());
    copyService = (CopyService) ctx.getBean("CopyService");
    this.policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
    this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    // authenticate
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    // start the transaction
    txn = getUserTransaction();
    txn.begin();
    
    // create a store and get the root node
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, getName());
    if (!nodeService.exists(storeRef))
    {
        storeRef = nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
    }
    rootNodeRef = nodeService.getRootNode(storeRef);

    ChildAssociationRef assocRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(TEST_NAMESPACE, GUID.generate()),
            ContentModel.TYPE_CONTENT);
    contentNodeRef = assocRef.getChildRef();

    ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
    writer.setEncoding("UTF-16");
    writer.setLocale(Locale.CHINESE);
    writer.setMimetype("text/plain");
    writer.putContent("sample content");
}
 
Example 28
public Map<String, Document> parseXMLDocuments(final String typeName, NodeRef rootNode, String repoPath)
        throws IOException, SAXException
{
    final Map<String, Document> result = new TreeMap<String, Document>();

    String[] pathElements = breakDownPath(repoPath);

    try
    {
        FileInfo file = fileService.resolveNamePath(rootNode, Arrays.asList(pathElements));

        if (file.isFolder())
        {
            QName typeQName = QName.createQName(typeName, namespaceService);
            Set<QName> types = new HashSet<QName>(dictionaryService.getSubTypes(typeQName, true));
            types.add(typeQName);
            List<ChildAssociationRef> children = nodeService.getChildAssocs(file.getNodeRef(), types);
            for (ChildAssociationRef child : children)
            {
                String name = (String) nodeService.getProperty(child.getChildRef(), ContentModel.PROP_NAME);
                Document doc = XMLUtil.parse(child.getChildRef(), contentService);
                result.put(name, doc);
            }
        }
    }
    catch (Exception ex)
    {
        log.warn("Unexpected exception caught in call to parseXMLDocuments", ex);
    }
    return result;
}
 
Example 29
private boolean isContentPresent(NodeRef nodeRef)
{
    ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); 
    if ((reader != null && reader.exists()))
    {
        return true;
    }
    return false;
}
 
Example 30
/**
 * Tests that when the deleteTag() method runs, it will remove invalid references to the deleted tag.
 */
@Test
@Category({RedundantTests.class,LuceneTests.class})
public void testDeleteTag() throws Exception{

    try{
        // We instruct the 'nodeRefPropInterceptor' to skip processing on the 'get' methods.
        // This is needed because this interceptor removes any properties which are invalid. e.g. have been deleted.
        // We need to make sure that the 'taggable' property stays put.
        nodeRefPropInterceptor.setFilterOnGet(false);

        this.transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>(){

            @SuppressWarnings("unchecked")
            @Override
            public Void execute() throws Throwable
            {
                taggingService.clearTags(folder);
                // addTag uses lucene to get a reference to the existing TAG_1 tag node.
                // this fails without lucene
                taggingService.addTag(folder, TAG_1);

                // The deleteTag() should remove any reference to the deleted tag
                List<NodeRef> taggableProperty = (List<NodeRef>) nodeService.getProperty(folder, ContentModel.PROP_TAGS);
                assertTrue("Our folder should have a reference on one tag.", taggableProperty.size() == 1);

                taggingService.deleteTag(TaggingServiceImplTest.storeRef, TAG_1);

                // The deleteTag() should remove any reference to the deleted tag
                taggableProperty = (List<NodeRef>) nodeService.getProperty(folder, ContentModel.PROP_TAGS);
                assertTrue("Our folder shouldn't have any references left to deleted tags.", taggableProperty.size() == 0);

                return null;
            }
        });
    } finally{
        nodeRefPropInterceptor.setFilterOnGet(true);
    }
}