Java Code Examples for org.alfresco.service.namespace.NamespaceService

The following are top voted examples for showing how to use org.alfresco.service.namespace.NamespaceService. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: alfresco-repository   File: EmailServiceImplTest.java   View source code 7 votes vote down vote up
@Override
public void setUp() throws Exception
{  
    AuthenticationUtil.setRunAsUserSystem();
    nodeService = (NodeService)ctx.getBean("NodeService");
    assertNotNull("nodeService", nodeService);
    authorityService = (AuthorityService)ctx.getBean("AuthorityService");
    assertNotNull("authorityService", authorityService);
    ChildApplicationContextFactory emailSubsystem = (ChildApplicationContextFactory) ctx.getBean("InboundSMTP");
    assertNotNull("emailSubsystem", emailSubsystem);
    ApplicationContext emailCtx = emailSubsystem.getApplicationContext();
    emailService = (EmailService)emailCtx.getBean("emailService");       
    assertNotNull("emailService", emailService);
    personService = (PersonService)emailCtx.getBean("PersonService");       
    assertNotNull("personService", personService);     
    namespaceService = (NamespaceService)emailCtx.getBean("NamespaceService");       
    assertNotNull("namespaceService", namespaceService);
    searchService = (SearchService)emailCtx.getBean("SearchService");  
    assertNotNull("searchService", searchService);
    folderEmailMessageHandler = (FolderEmailMessageHandler) emailCtx.getBean("folderEmailMessageHandler");  
    assertNotNull("folderEmailMessageHandler", folderEmailMessageHandler);
    transactionHelper = (RetryingTransactionHelper) emailCtx.getBean("retryingTransactionHelper");
    assertNotNull("transactionHelper", transactionHelper);
}
 
Example 2
Project: alfresco-remote-api   File: TestCMIS.java   View source code 6 votes vote down vote up
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 3
Project: alfresco-repository   File: MultiTDemoTest.java   View source code 6 votes vote down vote up
private NodeRef createFolderNode(NodeRef parentFolderNodeRef, String nameValue)
{
    if (nameValue != null)
    {       
        Map<QName, Serializable> folderProps = new HashMap<QName, Serializable>();
        folderProps.put(ContentModel.PROP_NAME, nameValue);
        
        return this.nodeService.createNode(
                parentFolderNodeRef, 
                ContentModel.ASSOC_CONTAINS, 
                QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nameValue),
                ContentModel.TYPE_FOLDER,
                folderProps).getChildRef();
    }
    
    return null;
}
 
Example 4
Project: alfresco-repository   File: MultiUserRenditionTest.java   View source code 6 votes vote down vote up
private NodeRef createPdfDocumentAsCurrentlyAuthenticatedUser(final String nodeName)
{
    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NAME, nodeName);
    NodeRef result = nodeService.createNode(testFolder, 
                                            ContentModel.ASSOC_CONTAINS, 
                                            QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName), 
                                            ContentModel.TYPE_CONTENT,
                                            props).getChildRef();
    
    File file = loadQuickPdfFile();

    // Set the content
    ContentWriter writer = contentService.getWriter(result, ContentModel.PROP_CONTENT, true);
    writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
    writer.setEncoding("UTF-8");
    
    writer.putContent(file);
    
    return result;
}
 
Example 5
Project: alfresco-repository   File: ThumbnailServiceImplTest.java   View source code 6 votes vote down vote up
/**
 * See REPO-2257, MNT-17661
 */
public void testLastThumbnailModificationDataContentCopy() throws Exception
{
    final NodeRef pdfOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_PDF);
    QName qname = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "doclib");

    ThumbnailDefinition details = thumbnailService.getThumbnailRegistry().getThumbnailDefinition(qname.getLocalName());
    NodeRef thumbnail = this.thumbnailService.createThumbnail(pdfOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG,
            details.getTransformationOptions(), "doclib");
    assertNotNull(thumbnail);

    setComplete();
    endTransaction();

    Thread.sleep(1000);

    // Get initial value of property "Last thumbnail modification data"
    List<String>lastThumbnailData = (List<String>)this.secureNodeService.getProperty(pdfOrig, ContentModel.PROP_LAST_THUMBNAIL_MODIFICATION_DATA);
    assertNotNull(lastThumbnailData);
    assertEquals(1, lastThumbnailData.size());
    assertTrue(lastThumbnailData.get(0).contains("doclib:"));

    final NodeRef pdfCopy = copyService.copy(pdfOrig, this.folder, ContentModel.ASSOC_CONTAINS, QName.createQName("copyOfOriginal"));
    List<String> lastThumbnailDataCopy = (List<String>)this.secureNodeService.getProperty(pdfCopy, ContentModel.PROP_LAST_THUMBNAIL_MODIFICATION_DATA);
    assertNull(lastThumbnailDataCopy);
}
 
Example 6
Project: alfresco-repository   File: OnCreateChildAssociationRuleTrigger.java   View source code 6 votes vote down vote up
/**
 * @see org.alfresco.repo.rule.ruletrigger.RuleTrigger#registerRuleTrigger()
 */
public void registerRuleTrigger()
{
	if (isClassBehaviour == true)
	{
		this.policyComponent.bindClassBehaviour(
				QName.createQName(NamespaceService.ALFRESCO_URI, POLICY_NAME), 
				this, 
				new JavaBehaviour(this, POLICY_NAME));
	}
	else
	{		
		this.policyComponent.bindAssociationBehaviour(
				QName.createQName(NamespaceService.ALFRESCO_URI, POLICY_NAME), 
				this, 
				new JavaBehaviour(this, POLICY_NAME));
	}
}
 
Example 7
Project: alfresco-data-model   File: ISO9075.java   View source code 6 votes vote down vote up
public static String getXPathName(QName qName, NamespacePrefixResolver nspr)
{

    Collection<String> prefixes = nspr.getPrefixes(qName.getNamespaceURI());
    if (prefixes.size() == 0)
    {
        throw new NamespaceException("A namespace prefix is not registered for uri " + qName.getNamespaceURI());
    }
    String prefix = prefixes.iterator().next();
    if (prefix.equals(NamespaceService.DEFAULT_PREFIX))
    {
        return ISO9075.encode(qName.getLocalName());
    }
    else
    {
        return prefix + ":" + ISO9075.encode(qName.getLocalName());
    }

}
 
Example 8
Project: alfresco-repository   File: RenditionNodeManagerTest.java   View source code 6 votes vote down vote up
public void testNoOldRenditionAndNoDestinationSpecifiedAndParentIsNotSource()
{
    String localName = "Foo";
    QName assocName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, localName);
    NodeRef parent = new NodeRef("http://test/parentId");
    ChildAssociationRef parentAssoc = makeAssoc(parent, destination, assocName, false);
    
    Map<QName, Serializable> indexProps = Collections.singletonMap(ContentModel.PROP_IS_INDEXED, (Serializable) Boolean.FALSE);
    when(nodeService.createNode(parent, ContentModel.ASSOC_CONTAINS, assocName, ContentModel.TYPE_CONTENT, indexProps))
        .thenReturn(parentAssoc);
    
    RenditionLocation location = new RenditionLocationImpl(parent, null, localName);
    RenditionNodeManager manager = new RenditionNodeManager(source, null, location, definition, nodeService, renditionService, behaviourFilter);
    ChildAssociationRef result = manager.findOrCreateRenditionNode();
    assertEquals(parentAssoc, result);
    // Check the rendition association is created.
    verify(nodeService).addChild(source, destination, RenditionModel.ASSOC_RENDITION, renditionName);
}
 
Example 9
Project: alfresco-repository   File: StartWorkflowActionExecuterTest.java   View source code 6 votes vote down vote up
/**
 * Called at the begining of all tests
 */
@SuppressWarnings("deprecation")
@Override
protected void onSetUpInTransaction() throws Exception
{
    this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
    this.namespaceService = (NamespaceService)this.applicationContext.getBean("namespaceService");
    this.personService = (PersonService)this.applicationContext.getBean("personService");
    
    AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
    
    // Create the store and get the root node
    rootNodeRef = nodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"));
    this.nodeRef = this.nodeService.createNode(
            this.rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName("{test}testnode"),
            ContentModel.TYPE_CONTENT).getChildRef();
    
    // Get the executer instance 
    this.executer = (StartWorkflowActionExecuter)this.applicationContext.getBean(StartWorkflowActionExecuter.NAME);
}
 
Example 10
Project: alfresco-repository   File: ViewParser.java   View source code 6 votes vote down vote up
/**
 * Process start of a node definition
 * 
 * @param xpp XmlPullParser
 * @param typeDef TypeDefinition
 * @param parserContext ParserContext
 * @throws XmlPullParserException
 * @throws IOException
 */
private void processStartType(XmlPullParser xpp, TypeDefinition typeDef, ParserContext parserContext)
    throws XmlPullParserException, IOException
{
    ParentContext parent = (ParentContext)parserContext.elementStack.peek();
    NodeContext node = new NodeContext(typeDef.getName(), parent, typeDef);

    // Extract child name if explicitly defined
    String childName = xpp.getAttributeValue(NamespaceService.REPOSITORY_VIEW_1_0_URI, VIEW_CHILD_NAME_ATTR);
    if (childName != null && childName.length() > 0)
    {
        node.setChildName(childName);
    }

    // Extract import id if explicitly defined
    String importId = xpp.getAttributeValue(NamespaceService.REPOSITORY_VIEW_1_0_URI, VIEW_ID_ATTR);
    if (importId != null && importId.length() > 0)
    {
        node.setImportId(importId);
    }
    
    parserContext.elementStack.push(node);
    
    if (logger.isDebugEnabled())
        logger.debug(indentLog("Pushed " + node, parserContext.elementStack.size() -1));
}
 
Example 11
Project: alfresco-repository   File: AbstractWorkflowServiceIntegrationTest.java   View source code 6 votes vote down vote up
protected void checkTaskQueryTaskCompleted(String workflowInstanceId, WorkflowTask theTask, WorkflowTask startTask) 
{
    List<String> expectedTasks = Arrays.asList(theTask.getId(), startTask.getId());
    checkProcessIdQuery(workflowInstanceId, expectedTasks, WorkflowTaskState.COMPLETED);
    
    // Adhoc task should only be returned
    QName taskName = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "adhocTask");
    checkTaskNameQuery(taskName, Arrays.asList(theTask.getId()), WorkflowTaskState.COMPLETED, workflowInstanceId);

    // Completed adhocTask is assigned to USER2
    checkActorIdQuery(USER2, Arrays.asList(theTask.getId()), WorkflowTaskState.COMPLETED, null);
    
    // Workflow is still active, both tasks will be returned
    checkIsActiveQuery(expectedTasks, WorkflowTaskState.COMPLETED, workflowInstanceId);
   
    // Both tasks have custom property set
    checkTaskPropsQuery(expectedTasks, WorkflowTaskState.COMPLETED, null);
}
 
Example 12
Project: alfresco-remote-api   File: AbstractWorkflowRestApiTest.java   View source code 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    ApplicationContext appContext = getServer().getApplicationContext();

    namespaceService = (NamespaceService) appContext.getBean("NamespaceService");
    workflowService = (WorkflowService) appContext.getBean("WorkflowService");
    MutableAuthenticationService authenticationService = (MutableAuthenticationService) appContext.getBean("AuthenticationService");
    PersonService personService = (PersonService) appContext.getBean("PersonService");
    SearchService searchService = (SearchService) appContext.getBean("SearchService");
    FileFolderService fileFolderService = (FileFolderService) appContext.getBean("FileFolderService");
    nodeService = (NodeService) appContext.getBean("NodeService");
    
    // for the purposes of the tests make sure workflow engine is enabled/visible.
    WorkflowAdminServiceImpl workflowAdminService = (WorkflowAdminServiceImpl) appContext.getBean("workflowAdminService");
    this.wfTestHelper = new WorkflowTestHelper(workflowAdminService, getEngine(), true);
    
    AuthorityService authorityService = (AuthorityService) appContext.getBean("AuthorityService");
    personManager = new TestPersonManager(authenticationService, personService, nodeService);
    groupManager = new TestGroupManager(authorityService);

    authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent");
    dictionaryService = (DictionaryService) appContext.getBean("dictionaryService");

    personManager.createPerson(USER1);
    personManager.createPerson(USER2);
    personManager.createPerson(USER3);

    authenticationComponent.setSystemUserAsCurrentUser();

    groupManager.addUserToGroup(GROUP, USER2);

    packageRef = workflowService.createPackage(null);

    NodeRef companyHome = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), COMPANY_HOME, null, namespaceService, false).get(0);

    contentNodeRef = fileFolderService.create(companyHome, TEST_CONTENT + System.currentTimeMillis(), ContentModel.TYPE_CONTENT).getNodeRef();

    authenticationComponent.clearCurrentSecurityContext();
}
 
Example 13
Project: alfresco-repository   File: SiteServiceImplMoreTest.java   View source code 5 votes vote down vote up
@BeforeClass public static void initStaticData() throws Exception
{
    AUTHORITY_SERVICE         = APP_CONTEXT_INIT.getApplicationContext().getBean("AuthorityService", AuthorityService.class);
    NAMESPACE_SERVICE         = APP_CONTEXT_INIT.getApplicationContext().getBean("namespaceService", NamespaceService.class);
    NODE_SERVICE              = APP_CONTEXT_INIT.getApplicationContext().getBean("NodeService", NodeService.class);
    NODE_ARCHIVE_SERVICE      = APP_CONTEXT_INIT.getApplicationContext().getBean("nodeArchiveService", NodeArchiveService.class);
    SITE_SERVICE              = APP_CONTEXT_INIT.getApplicationContext().getBean("siteService", SiteService.class);
    COCI_SERVICE              = APP_CONTEXT_INIT.getApplicationContext().getBean("checkOutCheckInService", CheckOutCheckInService.class);
    TRANSACTION_HELPER        = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    PERMISSION_SERVICE        = APP_CONTEXT_INIT.getApplicationContext().getBean("permissionServiceImpl", PermissionService.class);
    AUTHENTICATION_SERVICE    = APP_CONTEXT_INIT.getApplicationContext().getBean("authenticationService", MutableAuthenticationService.class);
    PERSON_SERVICE            = APP_CONTEXT_INIT.getApplicationContext().getBean("PersonService", PersonService.class);
    FILE_FOLDER_SERVICE       = APP_CONTEXT_INIT.getApplicationContext().getBean("FileFolderService",FileFolderService.class);
    AUTHENTICATION_COMPONENT  = APP_CONTEXT_INIT.getApplicationContext().getBean("authenticationComponent",AuthenticationComponent.class);
    LOCK_SERVICE              = APP_CONTEXT_INIT.getApplicationContext().getBean("lockService",LockService.class);
    
    // We'll create this test content as admin.
    final String admin = AuthenticationUtil.getAdminUserName();
    
    TEST_SITE_NAME = GUID.generate();
    TEST_SUB_SITE_NAME = GUID.generate();
    
    final QName subSiteType = QName.createQName("testsite", "testSubsite", NAMESPACE_SERVICE);
    
    STATIC_TEST_SITES.createSite("sitePreset", TEST_SITE_NAME, "siteTitle", "siteDescription", SiteVisibility.PUBLIC, admin);
    STATIC_TEST_SITES.createSite("sitePreset", TEST_SUB_SITE_NAME, "siteTitle", "siteDescription", SiteVisibility.PUBLIC, subSiteType, admin);
    
    TEST_SITE_WITH_MEMBERS = STATIC_TEST_SITES.createTestSiteWithUserPerRole(SiteServiceImplMoreTest.class.getSimpleName(), "sitePreset", SiteVisibility.PUBLIC, admin);
}
 
Example 14
Project: alfresco-repository   File: ActivitiSpringTest.java   View source code 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void setUp() throws Exception
{
    ConfigurableApplicationContext appContext = loadContext();
    this.repo = (RepositoryService) appContext.getBean("activitiRepositoryService");
    this.runtime = (RuntimeService) appContext.getBean("activitiRuntimeService");
    
    ServiceRegistry serviceRegistry = (ServiceRegistry) appContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent");
    TransactionService transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    txnHelper = transactionService.getRetryingTransactionHelper();

    // authenticate
    authenticationComponent.setSystemUserAsCurrentUser();
    
    StoreRef storeRef = nodeService.createStore(
            StoreRef.PROTOCOL_WORKSPACE,
            "test-" + getName() + "-" + System.currentTimeMillis());
    NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
    // Create a node to work on
    workingNodeRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, getName()),
            ContentModel.TYPE_CMOBJECT).getChildRef();

    String resource = "org/alfresco/repo/workflow/activiti/testTransaction.bpmn20.xml";
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream input= classLoader.getResourceAsStream(resource);
    this.deployment = repo.createDeployment()
    .addInputStream(resource, input)
    .deploy();
}
 
Example 15
Project: alfresco-repository   File: RepoTransferReceiverImplTest.java   View source code 5 votes vote down vote up
private TransferManifestNormalNode createFolderNode(String folderName) throws Exception
{
    TransferManifestNormalNode node = new TransferManifestNormalNode();
    String uuid = GUID.generate();
    NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, uuid);
    node.setNodeRef(nodeRef);
    node.setUuid(uuid);

    node.setType(ContentModel.TYPE_FOLDER);
    
    NodeRef parentFolder = repositoryHelper.getGuestHome();

    String nodeName = folderName == null ? uuid + ".folder" + getNameSuffix() : folderName;

    List<ChildAssociationRef> parents = new ArrayList<ChildAssociationRef>();
    ChildAssociationRef primaryAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parentFolder, QName
            .createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName), node.getNodeRef(), true, -1);
    parents.add(primaryAssoc);
    node.setParentAssocs(parents);
    node.setParentPath(nodeService.getPath(parentFolder));
    node.setPrimaryParentAssoc(primaryAssoc);

    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NODE_UUID, uuid);
    props.put(ContentModel.PROP_NAME, nodeName);
    node.setProperties(props);

    return node;
}
 
Example 16
Project: alfresco-repository   File: VersionServiceImplTest.java   View source code 5 votes vote down vote up
private NodeRef addComment(NodeRef nr, String comment, boolean suppressRollups)
{
    // There is no CommentService, so we have to create the node structure by hand.
    // This is what happens within e.g. comment.put.json.js when comments are submitted via the REST API.
    if (!nodeService.hasAspect(nr, ForumModel.ASPECT_DISCUSSABLE))
    {
        nodeService.addAspect(nr, ForumModel.ASPECT_DISCUSSABLE, null);
    }
    if (!nodeService.hasAspect(nr, ForumModel.ASPECT_COMMENTS_ROLLUP) && !suppressRollups)
    {
        nodeService.addAspect(nr, ForumModel.ASPECT_COMMENTS_ROLLUP, null);
    }
    // Forum node is created automatically by DiscussableAspect behaviour.
    NodeRef forumNode = nodeService.getChildAssocs(nr, ForumModel.ASSOC_DISCUSSION, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion")).get(0).getChildRef();
    
    final List<ChildAssociationRef> existingTopics = nodeService.getChildAssocs(forumNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Comments"));
    NodeRef topicNode = null;
    if (existingTopics.isEmpty())
    {
        topicNode = nodeService.createNode(forumNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Comments"), ForumModel.TYPE_TOPIC).getChildRef();
    }
    else
    {
        topicNode = existingTopics.get(0).getChildRef();
    }

    NodeRef postNode = nodeService.createNode(topicNode, ContentModel.ASSOC_CONTAINS, QName.createQName("comment" + System.currentTimeMillis()), ForumModel.TYPE_POST).getChildRef();
    nodeService.setProperty(postNode, ContentModel.PROP_CONTENT, new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null));
    ContentWriter writer = contentService.getWriter(postNode, ContentModel.PROP_CONTENT, true);
    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    writer.setEncoding("UTF-8");
    writer.putContent(comment);
    
    return postNode;
}
 
Example 17
Project: alfresco-test-assertions   File: WorkflowAssertTest.java   View source code 5 votes vote down vote up
/**
 * Creates and returns a workflow package. This package will contain the
 * given {@link NodeRef} <code>items</code>. The item name is used to create
 * a valid local name for the association between the package and the item.
 * The workflow package will contain only the existing items.
 *
 * @param items
 * @return {@link NodeRef} of the newly created workflow package
 */
private NodeRef createWorkflowPackage(final List<NodeRef> items) {
    ParameterCheck.mandatoryCollection("items", items);
    final NodeRef wfPackage = workflowService.createPackage(null);

    for (final NodeRef item : items) {
        if ((item != null) && nodeService.exists(item)) {
            final String itemName = (String) nodeService.getProperty(item, ContentModel.PROP_NAME);
            nodeService.addChild(wfPackage, item, WorkflowModel.ASSOC_PACKAGE_CONTAINS,
                            QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(itemName)));
        }
    }

    return wfPackage;
}
 
Example 18
Project: alfresco-repository   File: AuthorityDAOImpl.java   View source code 5 votes vote down vote up
public void init()
{
    // Listen out for person removals so that we can clear cached authorities
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"), ContentModel.TYPE_PERSON, new JavaBehaviour(
            this, "beforeDeleteNode"));
    // Listen out for updates to persons and authority containers to handle renames
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"), ContentModel.TYPE_AUTHORITY, new JavaBehaviour(
            this, "onUpdateProperties"));
}
 
Example 19
Project: alfresco-repository   File: ReferenceableAspect.java   View source code 5 votes vote down vote up
/**
 * Initialise the Referencable Aspect
 * <p>
 * Ensures that the {@link ContentModel#ASPECT_REFERENCEABLE referencable aspect}
 * copy behaviour is disabled.
 */
public void init()
{
    // disable copy for referencable aspect
    this.policyComponent.bindClassBehaviour(
            QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"),
            ContentModel.ASPECT_REFERENCEABLE,
            new JavaBehaviour(this, "getCopyCallback"));
}
 
Example 20
Project: alfresco-repository   File: ActivitiWorkflowServiceIntegrationTest.java   View source code 5 votes vote down vote up
public void testReviewAndPooledNotModifiedDate()
{
    authenticationComponent.setSystemUserAsCurrentUser();
    
    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NAME, "MNT-11522-testfile.txt");
    final ChildAssociationRef childAssoc = nodeService.createNode(companyHome, ContentModel.ASSOC_CONTAINS,
            QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "MNT-11522-test"), ContentModel.TYPE_CONTENT, props);
    NodeRef addedNodeRef = childAssoc.getChildRef();
    Date lastModifiedDate = (Date)nodeService.getProperty(addedNodeRef, ContentModel.PROP_MODIFIED);        
    WorkflowDefinition definition = deployDefinition(getPooledReviewDefinitionPath());
    
    assertNotNull(definition);
    
    // Create workflow parameters
    Map<QName, Serializable> params = new HashMap<QName, Serializable>();
    NodeRef workflowPackage = workflowService.createPackage(null);
    params.put(WorkflowModel.ASSOC_PACKAGE, workflowPackage);
    NodeRef group = groupManager.get(GROUP);
    assertNotNull(group);
    params.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE, group);
    
    nodeService.addChild(workflowPackage, addedNodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
            QName.createValidLocalName((String) nodeService.getProperty(addedNodeRef, ContentModel.PROP_NAME))));
    
    WorkflowPath workflowPath = workflowService.startWorkflow(definition.getId(), params);
    assertNotNull(workflowPath);
    assertTrue(workflowPath.isActive());
    final String workflowInstanceId = workflowPath.getInstance().getId();

    List<WorkflowTask> pooledTasks = workflowService.getPooledTasks(GROUP);
    assertNotNull(pooledTasks);

    // End start task to progress workflow
    WorkflowTask startTask = workflowService.getStartTask(workflowInstanceId);
    String startTaskId = startTask.getId();
    workflowService.endTask(startTaskId, null);
    
    assertEquals(lastModifiedDate, nodeService.getProperty(addedNodeRef, ContentModel.PROP_MODIFIED));
}
 
Example 21
Project: alfresco-repository   File: LanguagesTest.java   View source code 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    
    // start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();

    // downgrade integrity
    IntegrityChecker.setWarnInTransaction();

    // authenticate
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    // create a test store
    StoreRef storeRef = nodeService
            .createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);

    // create a folder to import into
    workingRootNodeRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.ALFRESCO_URI, "working root"),
            ContentModel.TYPE_FOLDER).getChildRef();
}
 
Example 22
Project: alfresco-repository   File: ContentUsageImpl.java   View source code 5 votes vote down vote up
/**
 * The initialise method
 */
public void init()
{
    if (enabled)
    {
        // Register interest in the onUpdateProperties policy - for content
        policyComponent.bindClassBehaviour(
                QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"),
                ContentModel.TYPE_CONTENT,
                new JavaBehaviour(this, "onUpdateProperties"));
        
        // Register interest in the beforeDeleteNode policy - for content
        policyComponent.bindClassBehaviour(
                QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
                ContentModel.TYPE_CONTENT,
                new JavaBehaviour(this, "beforeDeleteNode"));
        
        // Register interest in the onCreateNode policy - for content
        policyComponent.bindClassBehaviour(
                QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"),
                ContentModel.TYPE_CONTENT,
                new JavaBehaviour(this, "onCreateNode"));
        
        /*
        // Register interest in the onAddAspect policy - for ownable
        policyComponent.bindClassBehaviour(
                QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"),
                ContentModel.ASPECT_OWNABLE,
                new JavaBehaviour(this, "onAddAspect"));
        */
    }
}
 
Example 23
Project: alfresco-repository   File: TaskFormProcessorTest.java   View source code 5 votes vote down vote up
private TypeDefinition makeTypeDef()
{
    TypeDefinition typeDef = mock(TypeDefinition.class);
    QName name = QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, TASK_DEF_NAME);
    when(typeDef.getName()).thenReturn(name);

    // Set up task property definitions
    Map<QName, PropertyDefinition> propertyDefs = makeTaskPropertyDefs();
    when(typeDef.getProperties()).thenReturn(propertyDefs);

    // Set up task association definitions.
    Map<QName, AssociationDefinition> associationDefs = makeTaskAssociationDefs();
    when(typeDef.getAssociations()).thenReturn(associationDefs);
    return typeDef;
}
 
Example 24
Project: alfresco-repository   File: StandardRenditionLocationResolverTest.java   View source code 5 votes vote down vote up
private NodeRef makeNode(NodeRef parent, QName nodeType)
{
    String uuid = GUID.generate();
    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NAME, uuid);
    ChildAssociationRef assoc = nodeService.createNode(parent, ContentModel.ASSOC_CONTAINS, QName.createQName(
                NamespaceService.CONTENT_MODEL_1_0_URI, uuid), nodeType, props);
    return assoc.getChildRef();
}
 
Example 25
Project: alfresco-repository   File: ScriptUtils.java   View source code 5 votes vote down vote up
/**
 * Function to check if a module is installed
 * 
 * @param moduleName	module name (e.g. "org.alfresco.module.foo")
 * @return boolean      true if the module is currently installed
 */
public boolean moduleInstalled(String moduleName)
{
    ModuleService moduleService = (ModuleService)this.services.getService(QName.createQName(NamespaceService.ALFRESCO_URI, "ModuleService"));
    if (moduleService != null)
    {
        ModuleDetails moduleDetail = (ModuleDetails)moduleService.getModule(moduleName);
        return (moduleDetail != null);
    }
    return false;
}
 
Example 26
Project: alfresco-repository   File: AuditComponentTest.java   View source code 5 votes vote down vote up
/**
 * Test for <a href="https://issues.alfresco.com/jira/browse/MNT-11072">MNT-11072</a>
 * @throws Exception 
 */
public void testAuditInReadOnly() throws Exception
{
    QName veto = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "TestVeto");
    transactionServiceImpl.setAllowWrite(false, veto);
    try
    {
        auditAction02("action-02");
    }
    finally
    {
        transactionServiceImpl.setAllowWrite(true, veto);   
    }
}
 
Example 27
Project: alfresco-repository   File: RenditionedAspect.java   View source code 5 votes vote down vote up
/**
 * Initialise method
 */
public void init()
{
    this.policyComponent.bindClassBehaviour(
            QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"), 
            RenditionModel.ASPECT_RENDITIONED, 
            new JavaBehaviour(this, "onUpdateProperties", Behaviour.NotificationFrequency.EVERY_EVENT));
    this.policyComponent.bindClassBehaviour(
            QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"), 
            RenditionModel.ASPECT_RENDITIONED, 
            new JavaBehaviour(this, "getCopyCallback"));
}
 
Example 28
Project: alfresco-repository   File: ConcurrentNodeServiceSearchTest.java   View source code 5 votes vote down vote up
private NamespacePrefixResolver getNamespacePrefixReolsver(String defaultURI)
{
    DynamicNamespacePrefixResolver nspr = new DynamicNamespacePrefixResolver(null);
    nspr.registerNamespace(NamespaceService.SYSTEM_MODEL_PREFIX, NamespaceService.SYSTEM_MODEL_1_0_URI);
    nspr.registerNamespace(NamespaceService.CONTENT_MODEL_PREFIX, NamespaceService.CONTENT_MODEL_1_0_URI);
    nspr.registerNamespace(NamespaceService.APP_MODEL_PREFIX, NamespaceService.APP_MODEL_1_0_URI);
    nspr.registerNamespace("namespace", "namespace");
    nspr.registerNamespace(NamespaceService.DEFAULT_PREFIX, defaultURI);
    return nspr;
}
 
Example 29
Project: alfresco-repository   File: TaskFormProcessor.java   View source code 5 votes vote down vote up
public TaskFormProcessor(WorkflowService workflowService, NamespaceService namespaceService,
        DictionaryService dictionaryService, AuthenticationService authenticationService,
        PersonService personService, FieldProcessorRegistry fieldProcessorRegistry)
{
    this.workflowService = workflowService;
    this.namespaceService = namespaceService;
    this.dictionaryService = dictionaryService;
    this.authenticationService = authenticationService;
    this.personService = personService;
    this.fieldProcessorRegistry = fieldProcessorRegistry;
}
 
Example 30
Project: alfresco-repository   File: DefaultFieldBuilder.java   View source code 5 votes vote down vote up
public DefaultFieldBuilder(FormCreationData data,
        FieldProcessorRegistry registry,
        NamespaceService namespaceService,
        List<String> ignoredFields)
{
    this(data, registry, namespaceService, ignoredFields, MY_LOGGER);
}
 
Example 31
Project: alfresco-repository   File: RepoTransferReceiverImplTest.java   View source code 5 votes vote down vote up
/**
 * @return
 */
private TransferManifestNormalNode createContentNode(/*String transferId*/) throws Exception
{
    TransferManifestNormalNode node = new TransferManifestNormalNode();
    String uuid = GUID.generate();
    NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, uuid);
    node.setNodeRef(nodeRef);
    node.setUuid(uuid);
    byte[] dummyContent = "This is some dummy content.".getBytes("UTF-8");

    node.setType(ContentModel.TYPE_CONTENT);
    
    /**
     * Get guest home
     */
    NodeRef parentFolder = guestHome;

    String nodeName = uuid + ".testnode" + getNameSuffix();

    List<ChildAssociationRef> parents = new ArrayList<ChildAssociationRef>();
    ChildAssociationRef primaryAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parentFolder, QName
            .createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName), node.getNodeRef(), true, -1);
    parents.add(primaryAssoc);
    node.setParentAssocs(parents);
    node.setParentPath(nodeService.getPath(parentFolder));
    node.setPrimaryParentAssoc(primaryAssoc);

    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NODE_UUID, uuid);
    props.put(ContentModel.PROP_NAME, nodeName);
    ContentData contentData = new ContentData("/" + uuid, "text/plain", dummyContent.length, "UTF-8");
    props.put(ContentModel.PROP_CONTENT, contentData);
    node.setProperties(props);

    return node;
}
 
Example 32
Project: alfresco-repository   File: DBScore.java   View source code 5 votes vote down vote up
@Override
public void prepare(NamespaceService namespaceService, DictionaryService dictionaryService, QNameDAO qnameDAO, NodeDAO nodeDAO, TenantService tenantService, Set<String> selectors,
        Map<String, Argument> functionArgs, FunctionEvaluationContext functionContext, boolean supportBooleanFloatAndDouble)
{
    // TODO Auto-generated method stub
    
}
 
Example 33
Project: alfresco-expirable-content   File: DeleteExpiredDocumentsTest.java   View source code 5 votes vote down vote up
@Test
public void testDeleteDocs() {
    AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME);

    String query = "+PATH:\"/app:company_home/app:dictionary/app:expirable_content_reports\"";
    ResultSet rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_FTS_ALFRESCO, query);

    NodeRef reportsFolder = rs.getNodeRef(0);


    String testFolderName = "testFolder-" + (new Date()).getTime();
    Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
    contentProps.put(ContentModel.PROP_NAME, testFolderName);
    NodeRef testFolder = nodeService.createNode(reportsFolder,
            ContentModel.ASSOC_CONTAINS,
            QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, testFolderName),
            ContentModel.TYPE_FOLDER,
            contentProps).getChildRef();

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -1);
    Date yesterday = cal.getTime();

    createTestDoc(testFolder, "testDoc1", yesterday);
    createTestDoc(testFolder, "testDoc2", yesterday);
    createTestDoc(testFolder, "testDoc3", null); // does not expire

    List<ChildAssociationRef> children = nodeService.getChildAssocs(testFolder);
    assertEquals(3, children.size());

    Action deleteExpiredAction = actionService.createAction("delete-expired-content");
    actionService.executeAction(deleteExpiredAction, null);

    children = nodeService.getChildAssocs(testFolder);
    assertEquals(1, children.size());

    nodeService.deleteNode(testFolder);
}
 
Example 34
Project: alfresco-repository   File: ActionServiceImpl2Test.java   View source code 5 votes vote down vote up
private NodeRef addTempScript(final String scriptFileName, final String javaScript)
{
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    return transactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
    {
        public NodeRef execute() throws Throwable
        {

            // get the company_home
            NodeRef companyHomeRef = wellKnownNodes.getCompanyHome();
            // get the Data Dictionary
            NodeRef dataDictionaryRef = nodeService.getChildByName(companyHomeRef, ContentModel.ASSOC_CONTAINS,
                    "Data Dictionary");
            // get the Scripts
            NodeRef scriptsRef = nodeService.getChildByName(dataDictionaryRef, ContentModel.ASSOC_CONTAINS,
                    "Scripts");

            // Create the script node reference
            NodeRef script = nodeService.createNode(scriptsRef, ContentModel.ASSOC_CONTAINS,
                    QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, scriptFileName),
                    ContentModel.TYPE_CONTENT).getChildRef();

            nodeService.setProperty(script, ContentModel.PROP_NAME, scriptFileName);

            ContentWriter contentWriter = contentService.getWriter(script, ContentModel.PROP_CONTENT, true);
            contentWriter.setMimetype(MimetypeMap.MIMETYPE_JAVASCRIPT);
            contentWriter.setEncoding("UTF-8");
            contentWriter.putContent(javaScript);

            tempNodes.addNodeRef(script);              
            return script;
        }
    });
}
 
Example 35
Project: alfresco-repository   File: FieldUtils.java   View source code 5 votes vote down vote up
/**
 * Generates a list of association fields with values.
 * 
 * @param assocDefAndValue Map of association definitions and corresponding values
 * @param group The group the field belongs to
 * @param namespaceService NamespaceService instance
 * @return List of generated Field objects
 */
public static List<Field> makeAssociationFields(
            Map<AssociationDefinition, Object> assocDefAndValue,
            FieldGroup group,
            NamespaceService namespaceService,
            DictionaryService dictionaryService)
{
    return makeAssociationFields(assocDefAndValue.keySet(), assocDefAndValue, group, namespaceService, dictionaryService);
}
 
Example 36
Project: alfresco-repository   File: MockFieldProcessorRegistry.java   View source code 5 votes vote down vote up
public MockFieldProcessorRegistry(NamespaceService namespaceService, DictionaryService dictionaryService)
{
    register(PROP, makePropertyFieldProcessor(namespaceService, dictionaryService));
    register(ASSOC, makeAssociationFieldProcessor(namespaceService, dictionaryService));
    register(EncodingFieldProcessor.KEY, makeEncodingFieldProcessor());
    register(MimetypeFieldProcessor.KEY, makeMimetypeFieldProcessor());
    register(SizeFieldProcessor.KEY, makeSizeFieldProcessor());
    register(TransitionFieldProcessor.KEY, makeTransitionFieldProcessor());
    register(PackageItemsFieldProcessor.KEY, makePackageItemFieldProcessor());
    register(MessageFieldProcessor.KEY, makeMessageFieldProcessor());
    register(TaskOwnerFieldProcessor.KEY, makeTaskOwnerFieldProcessor());
    setDefaultProcessor(makeDefaultFieldProcessor(namespaceService, dictionaryService));
}
 
Example 37
Project: alfresco-repository   File: UsageQuotaProtector.java   View source code 5 votes vote down vote up
/**
 * The initialise method     
 */
public void init()
{    
    if (contentUsageService.getEnabled())
    {
        // Register interest in the onUpdateProperties policy
        policyComponent.bindClassBehaviour(
                QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"), 
                ContentModel.TYPE_PERSON, 
                new JavaBehaviour(this, "onUpdateProperties"));
    }
}
 
Example 38
Project: alfresco-repository   File: MockFieldProcessorRegistry.java   View source code 5 votes vote down vote up
private AssociationFieldProcessor makeAssociationFieldProcessor(NamespaceService namespaceService,
        DictionaryService dictionaryService)
{
    AssociationFieldProcessor processor = new AssociationFieldProcessor();
    processor.setDictionaryService(dictionaryService);
    processor.setNamespaceService(namespaceService);
    return processor;
}
 
Example 39
Project: alfresco-repository   File: ActionServiceImpl.java   View source code 5 votes vote down vote up
public void init()
{
    PropertyCheck.mandatory(this, "policyComponent", policyComponent);

    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"),
                ActionModel.TYPE_ACTION_PARAMETER, new JavaBehaviour(this, "getCopyCallback"));
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyComplete"),
                ActionModel.TYPE_ACTION_PARAMETER, new JavaBehaviour(this, "onCopyComplete"));
}
 
Example 40
Project: alfresco-repository   File: CommentsTest.java   View source code 5 votes vote down vote up
/**
 * This method applies the specified comment to the specified node.
 * As there is no CommentService or DiscussionService, we mimic here what the comments REST API does,
 * by manually creating the correct content structure using the nodeService. Behaviours will do some
 * of the work for us. See comments.post.json.js for comparison.
 * @param nr nodeRef to comment on.
 * @param comment the text of the comment.
 * @param suppressRollups if true, commentsRollup aspect will not be added.
 * @return the NodeRef of the fm:post comment node.
 * 
 * @see CommentsTest#testRollupOfPreSwiftNodes() for use of suppressRollups.
 */
private NodeRef applyComment(NodeRef nr, String comment, boolean suppressRollups)
{
    // There is no CommentService, so we have to create the node structure by hand.
    // This is what happens within e.g. comment.put.json.js when comments are submitted via the REST API.
    if (!nodeService.hasAspect(nr, ForumModel.ASPECT_DISCUSSABLE))
    {
        nodeService.addAspect(nr, ForumModel.ASPECT_DISCUSSABLE, null);
    }
    if (!nodeService.hasAspect(nr, ForumModel.ASPECT_COMMENTS_ROLLUP) && !suppressRollups)
    {
        nodeService.addAspect(nr, ForumModel.ASPECT_COMMENTS_ROLLUP, null);
    }
    // Forum node is created automatically by DiscussableAspect behaviour.
    NodeRef forumNode = nodeService.getChildAssocs(nr, ForumModel.ASSOC_DISCUSSION, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion")).get(0).getChildRef();
    
    final List<ChildAssociationRef> existingTopics = nodeService.getChildAssocs(forumNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Comments"));
    NodeRef topicNode = null;
    if (existingTopics.isEmpty())
    {
        topicNode = nodeService.createNode(forumNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Comments"), ForumModel.TYPE_TOPIC).getChildRef();
    }
    else
    {
        topicNode = existingTopics.get(0).getChildRef();
    }

    NodeRef postNode = nodeService.createNode(topicNode, ContentModel.ASSOC_CONTAINS, QName.createQName("comment" + System.currentTimeMillis()), ForumModel.TYPE_POST).getChildRef();
    nodeService.setProperty(postNode, ContentModel.PROP_CONTENT, new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null));
    ContentWriter writer = contentService.getWriter(postNode, ContentModel.PROP_CONTENT, true);
    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    writer.setEncoding("UTF-8");
    writer.putContent(comment);
    
    return postNode;
}