static Object generateDataByDataTypeProperty(
     QName dataType, String defaultValue, PropertyDefinition property) throws Exception {
   // TODO � introduire: gestion des contraintes
   Object randomData = null;
   if (dataType.equals(DataTypeDefinition.BOOLEAN)) {
     randomData = generateRandomBoolean();
   } else if (dataType.equals(DataTypeDefinition.INT)) {
     randomData = generateRandomInteger();
   } else if (dataType.equals(DataTypeDefinition.LONG)) {
     randomData = generateRandomLong();
   } else if (dataType.equals(DataTypeDefinition.FLOAT)) {
     randomData = generateRandomFloat();
   } else if (dataType.equals(DataTypeDefinition.DOUBLE)) {
     randomData = generateRandomDouble();
   } else if (dataType.equals(DataTypeDefinition.DATE)) {
     randomData = generateRandomDate();
   } else if (dataType.equals(DataTypeDefinition.DATETIME)) {
     randomData = generateRandomDateTime();
   } else if (dataType.equals(DataTypeDefinition.TEXT)) {
     randomData = generateRandomString(defaultValue, property);
   } else if (dataType.equals(DataTypeDefinition.ANY)) {
     randomData = generateRandomObject();
   } else {
     throw new Exception("Data type " + dataType.toString() + "is not take into account.");
   }
   return randomData;
 }
  @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;
  }
Example #3
0
  /* (non-Javadoc)
   * @see org.alfresco.service.cmr.view.Exporter#startNode(org.alfresco.service.cmr.repository.NodeRef)
   */
  public void startNode(NodeRef nodeRef) {
    try {
      AttributesImpl attrs = new AttributesImpl();

      Path path = nodeService.getPath(nodeRef);
      if (path.size() > 1) {
        // a child name does not exist for root
        Path.ChildAssocElement pathElement = (Path.ChildAssocElement) path.last();
        QName childQName = pathElement.getRef().getQName();
        attrs.addAttribute(
            NamespaceService.REPOSITORY_VIEW_1_0_URI,
            CHILDNAME_LOCALNAME,
            CHILDNAME_QNAME.toPrefixString(),
            null,
            toPrefixString(childQName));
      }

      QName type = nodeService.getType(nodeRef);
      contentHandler.startElement(
          type.getNamespaceURI(), type.getLocalName(), toPrefixString(type), attrs);
    } catch (SAXException e) {
      throw new ExporterException(
          "Failed to process start node event - node ref " + nodeRef.toString(), e);
    }
  }
Example #4
0
    public Builder(String typeName_) {
      // String tableName = tagResolver.translate(typeName_);
      String tableName = databaseDictionary.resolveClassAsTableName(typeName_);
      if (tableName == null) {
        throw new InvalidTypeException(typeName_);
      }

      Collection<QName> allTypes = dictionaryService.getAllTypes();
      List<QName> correspondingTypes = new ArrayList<QName>();
      for (QName type : allTypes) {
        if (type.getLocalName().equals(typeName_)) {
          correspondingTypes.add(type);
        }
      }
      if (correspondingTypes.size() == 0) {
        throw new AlfrescoRuntimeException(
            "Cannot find type \"" + typeName_ + "\" in Alfresco types");
      }
      if (correspondingTypes.size() > 1) {
        throw new AlfrescoRuntimeException(
            "Type \"" + typeName_ + "\" has several corresponding Alfresco types");
      }

      typeQName = correspondingTypes.get(0);
      namespaceURI = typeQName.getNamespaceURI();
      this.tableName = tableName;
      this.typeName = typeName_;
    }
Example #5
0
 public void testEndTask() {
   WorkflowDefinition workflowDef = getTestDefinition();
   Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
   parameters.put(
       QName.createQName(NamespaceService.DEFAULT_URI, "reviewer"),
       AuthenticationUtil.getAdminUserName());
   parameters.put(QName.createQName(NamespaceService.DEFAULT_URI, "testNode"), rootNodeRef);
   parameters.put(
       QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "package"),
       packageComponent.createPackage(null));
   WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), parameters);
   assertNotNull(path);
   List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
   assertNotNull(tasks1);
   assertEquals(1, tasks1.size());
   assertEquals(WorkflowTaskState.IN_PROGRESS, tasks1.get(0).getState());
   WorkflowTask updatedTask = taskComponent.endTask(tasks1.get(0).getId(), null);
   assertNotNull(updatedTask);
   assertEquals(WorkflowTaskState.COMPLETED, updatedTask.getState());
   List<WorkflowTask> completedTasks =
       taskComponent.getAssignedTasks(
           AuthenticationUtil.getAdminUserName(), WorkflowTaskState.COMPLETED);
   assertNotNull(completedTasks);
   completedTasks = filterTasksByWorkflowInstance(completedTasks, path.getInstance().getId());
   assertEquals(1, completedTasks.size());
   assertEquals(WorkflowTaskState.COMPLETED, completedTasks.get(0).getState());
 }
  /** Tests for various MP3 specific bits of metadata */
  public void testFileSpecificMetadata(String mimetype, Map<QName, Serializable> properties) {
    QName songTitle = QName.createQName("music", "songTitle");
    assertEquals(
        "Property " + songTitle + " not found for mimetype " + mimetype,
        QUICK_TITLE,
        DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(songTitle)));

    QName songArtist = QName.createQName("music", "artist");
    assertEquals(
        "Property " + songArtist + " not found for mimetype " + mimetype,
        ARTIST,
        DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(songArtist)));

    // Description is a composite - check the artist part
    assertContains(
        "Property "
            + ContentModel.PROP_DESCRIPTION
            + " didn't contain "
            + ARTIST
            + " for mimetype "
            + mimetype,
        ARTIST,
        DefaultTypeConverter.INSTANCE.convert(
            String.class, properties.get(ContentModel.PROP_DESCRIPTION)));
  }
  public void testAlfrescoCheckoutDoesNotModifyNode() {
    String adminUser = AuthenticationUtil.getAdminUserName();
    AuthenticationUtil.setFullyAuthenticatedUser(adminUser);

    Serializable initModifier = nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIER);
    Serializable initModified = nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
    assertFalse("The initial modifier should not be Admin!", adminUser.equals(initModifier));

    NodeRef copy =
        cociService.checkout(
            nodeRef, rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("workingCopy"));

    Serializable modifier = nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIER);
    assertEquals("Checkout should not cause the modifier to change!", initModifier, modifier);
    Serializable modified = nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
    assertEquals("Checkout should not cause the modified date to change!", initModified, modified);

    cociService.cancelCheckout(copy);
    modifier = nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIER);
    assertEquals(
        "Cancel checkout should not cause the modifier to change!", initModifier, modifier);
    modified = nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
    assertEquals(
        "Cancel checkout should not cause the modified date to change!", initModified, modified);

    copy =
        cociService.checkout(
            nodeRef, rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("workingCopy"));
    Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
    versionProperties.put(Version.PROP_DESCRIPTION, "This is a test version");
    cociService.checkin(copy, versionProperties);

    modifier = nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIER);
    assertEquals("The modifier should change to Admin after checkin!", adminUser, modifier);
  }
  /** @return Returns true if the pattern is present, otherwise false. */
  public boolean like(
      NodeRef nodeRef, QName propertyQName, String sqlLikePattern, boolean includeFTS) {
    if (propertyQName == null) {
      throw new IllegalArgumentException("Property QName is mandatory for the like expression");
    }

    StringBuilder sb = new StringBuilder(sqlLikePattern.length() * 3);

    if (includeFTS) {
      // convert the SQL-like pattern into a Lucene-compatible string
      String pattern =
          SearchLanguageConversion.convertXPathLikeToLucene(sqlLikePattern.toLowerCase());

      // build Lucene search string specific to the node
      sb = new StringBuilder();
      sb.append("+ID:\"").append(nodeRef.toString()).append("\" +(");
      // FTS or attribute matches
      if (includeFTS) {
        sb.append("TEXT:(").append(pattern).append(") ");
      }
      if (propertyQName != null) {
        sb.append(" @")
            .append(
                SearchLanguageConversion.escapeLuceneQuery(
                    QName.createQName(
                            propertyQName.getNamespaceURI(),
                            ISO9075.encode(propertyQName.getLocalName()))
                        .toString()))
            .append(":(")
            .append(pattern)
            .append(")");
      }
      sb.append(")");

      ResultSet resultSet = null;
      try {
        resultSet = this.query(nodeRef.getStoreRef(), "lucene", sb.toString());
        boolean answer = resultSet.length() > 0;
        return answer;
      } finally {
        if (resultSet != null) {
          resultSet.close();
        }
      }
    } else {
      // convert the SQL-like pattern into a Lucene-compatible string
      String pattern =
          SearchLanguageConversion.convertXPathLikeToRegex(sqlLikePattern.toLowerCase());

      Serializable property = nodeService.getProperty(nodeRef, propertyQName);
      if (property == null) {
        return false;
      } else {
        String propertyString =
            DefaultTypeConverter.INSTANCE.convert(
                String.class, nodeService.getProperty(nodeRef, propertyQName));
        return propertyString.toLowerCase().matches(pattern);
      }
    }
  }
  public void testCheckOutCheckInWithTranslatableAspect() {
    // Create a node to be used as the translation
    NodeRef translationNodeRef =
        nodeService
            .createNode(
                rootNodeRef,
                ContentModel.ASSOC_CHILDREN,
                QName.createQName("translation"),
                ContentModel.TYPE_CONTENT)
            .getChildRef();

    nodeService.addAspect(
        this.nodeRef,
        QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "translatable"),
        null);
    nodeService.createAssociation(
        this.nodeRef,
        translationNodeRef,
        QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "translations"));

    // Check it out
    NodeRef workingCopy =
        cociService.checkout(
            this.nodeRef,
            this.rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName("workingCopy"));

    // Check it back in again
    Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
    versionProperties.put(Version.PROP_DESCRIPTION, "This is a test version");
    cociService.checkin(workingCopy, versionProperties);
  }
Example #10
0
  public void testScript() throws IOException {
    // deploy test script definition
    ClassPathResource processDef = new ClassPathResource("jbpmresources/test_script.xml");
    assertFalse(
        workflowComponent.isDefinitionDeployed(
            processDef.getInputStream(), MimetypeMap.MIMETYPE_XML));
    WorkflowDeployment deployment =
        workflowComponent.deployDefinition(processDef.getInputStream(), MimetypeMap.MIMETYPE_XML);
    assertNotNull(deployment);

    WorkflowDefinition workflowDef = deployment.getDefinition();
    Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
    parameters.put(QName.createQName(NamespaceService.DEFAULT_URI, "testNode"), rootNodeRef);
    parameters.put(
        QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "package"),
        packageComponent.createPackage(null));
    WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), parameters);
    assertNotNull(path);
    List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
    assertNotNull(tasks1);
    assertEquals(1, tasks1.size());
    assertEquals(WorkflowTaskState.IN_PROGRESS, tasks1.get(0).getState());
    WorkflowTask updatedTask = taskComponent.endTask(tasks1.get(0).getId(), null);
    assertNotNull(updatedTask);
  }
Example #11
0
  /**
   * Get a map of the sites custom properties
   *
   * @return map of names and values
   */
  public ScriptableQNameMap<String, CustomProperty> getCustomProperties() {
    if (this.customProperties == null) {
      // create the custom properties map
      ScriptNode siteNode = new ScriptNode(this.siteInfo.getNodeRef(), this.serviceRegistry);
      // set the scope, for use when converting props to javascript objects
      siteNode.setScope(scope);
      this.customProperties =
          new ContentAwareScriptableQNameMap<String, CustomProperty>(
              siteNode, this.serviceRegistry);

      Map<QName, Serializable> props = siteInfo.getCustomProperties();
      for (QName qname : props.keySet()) {
        // get the property value
        Serializable propValue = props.get(qname);

        // convert the value
        NodeValueConverter valueConverter = siteNode.new NodeValueConverter();
        Serializable value = valueConverter.convertValueForScript(qname, propValue);

        // get the type and label information from the dictionary
        String title = null;
        String type = null;
        PropertyDefinition propDef = this.serviceRegistry.getDictionaryService().getProperty(qname);
        if (propDef != null) {
          type = propDef.getDataType().getName().toString();
          title = propDef.getTitle(this.serviceRegistry.getDictionaryService());
        }

        // create the custom property and add to the map
        CustomProperty customProp = new CustomProperty(qname.toString(), value, type, title);
        this.customProperties.put(qname.toString(), customProp);
      }
    }
    return this.customProperties;
  }
Example #12
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#endACL(org.alfresco.service.cmr.repository.NodeRef)
  */
 public void endACL(NodeRef nodeRef) {
   try {
     contentHandler.endElement(
         ACL_QNAME.getNamespaceURI(), ACL_QNAME.getLocalName(), toPrefixString(ACL_QNAME));
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process end ACL event - node ref " + nodeRef.toString());
   }
 }
Example #13
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#endNode(org.alfresco.service.cmr.repository.NodeRef)
  */
 public void endNode(NodeRef nodeRef) {
   try {
     QName type = nodeService.getType(nodeRef);
     contentHandler.endElement(type.getNamespaceURI(), type.getLocalName(), toPrefixString(type));
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process end node event - node ref " + nodeRef.toString(), e);
   }
 }
Example #14
0
 public static long getCrc(QName qname) {
   CRC32 crc = new CRC32();
   try {
     crc.update(qname.getNamespaceURI().getBytes("UTF-8"));
     crc.update(qname.getLocalName().getBytes("UTF-8"));
   } catch (UnsupportedEncodingException e) {
     throw new RuntimeException("UTF-8 encoding is not supported");
   }
   return crc.getValue();
 }
Example #15
0
  /**
   * 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;
  }
Example #16
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#endAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
  */
 public void endAspect(NodeRef nodeRef, QName aspect) {
   try {
     contentHandler.endElement(
         aspect.getNamespaceURI(), aspect.getLocalName(), toPrefixString(aspect));
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process end aspect event - node ref "
             + nodeRef.toString()
             + "; aspect "
             + toPrefixString(aspect),
         e);
   }
 }
Example #17
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#startAssoc(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
  */
 public void startAssoc(NodeRef nodeRef, QName assoc) {
   try {
     contentHandler.startElement(
         assoc.getNamespaceURI(), assoc.getLocalName(), toPrefixString(assoc), EMPTY_ATTRIBUTES);
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process start assoc event - nodeRef "
             + nodeRef
             + "; association "
             + toPrefixString(assoc),
         e);
   }
 }
Example #18
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#endAssoc(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
  */
 public void endAssoc(NodeRef nodeRef, QName assoc) {
   try {
     contentHandler.endElement(
         assoc.getNamespaceURI(), assoc.getLocalName(), toPrefixString(assoc));
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process end assoc event - nodeRef "
             + nodeRef
             + "; association "
             + toPrefixString(assoc),
         e);
   }
 }
Example #19
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#endProperty(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
  */
 public void endProperty(NodeRef nodeRef, QName property) {
   try {
     contentHandler.endElement(
         property.getNamespaceURI(), property.getLocalName(), toPrefixString(property));
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process end property event - nodeRef "
             + nodeRef
             + "; property "
             + toPrefixString(property),
         e);
   }
 }
  /**
   * Convert Alfresco authority to actor id
   *
   * @param authority
   * @return actor id
   */
  private String mapAuthorityToName(ScriptNode authority, boolean allowGroup) {
    String name = null;
    QName type = authority.getQNameType();

    if (dictionaryService.isSubClass(type, ContentModel.TYPE_PERSON)) {
      name = (String) authority.getProperties().get(ContentModel.PROP_USERNAME);
    } else if (allowGroup
        && dictionaryService.isSubClass(type, ContentModel.TYPE_AUTHORITY_CONTAINER)) {
      name = authorityDAO.getAuthorityName(authority.getNodeRef());
    } else if (type.equals(ContentModel.TYPE_AUTHORITY)) {
      name = authorityDAO.getAuthorityName(authority.getNodeRef());
    }
    return name;
  }
 /** Initialise method */
 public void init() {
   // All forum-related copy behaviour uses the same copy callback
   this.policyComponent.bindClassBehaviour(
       QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"),
       ForumModel.ASPECT_DISCUSSABLE,
       new JavaBehaviour(this, "onAddAspect"));
   this.policyComponent.bindClassBehaviour(
       QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"),
       ForumModel.ASPECT_DISCUSSABLE,
       new JavaBehaviour(this, "getCopyCallback"));
   this.policyComponent.bindClassBehaviour(
       QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyComplete"),
       ForumModel.ASPECT_DISCUSSABLE,
       new JavaBehaviour(this, "onCopyComplete"));
 }
Example #22
0
 public void setQName(QNameDAO qnameDAO, QName qname) {
   String assocQNameNamespace = qname.getNamespaceURI();
   String assocQNameLocalName = qname.getLocalName();
   Long assocQNameNamespaceId = qnameDAO.getOrCreateNamespace(assocQNameNamespace).getFirst();
   Long assocQNameCrc = getCrc(qname);
   // get write lock
   refWriteLock.lock();
   try {
     setQnameNamespaceId(assocQNameNamespaceId);
     setQnameLocalName(assocQNameLocalName);
     setQnameCrc(assocQNameCrc);
   } finally {
     refWriteLock.unlock();
   }
 }
  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;
  }
  private NodeRef createFolderWithPermission(NodeRef parent, String username, String permission) {
    // Authenticate as system user because the current user should not be node owner
    AuthenticationComponent authenticationComponent =
        (AuthenticationComponent) this.applicationContext.getBean("authenticationComponent");
    authenticationComponent.setSystemUserAsCurrentUser();

    // Create the folder
    NodeRef folder =
        nodeService
            .createNode(
                parent,
                ContentModel.ASSOC_CHILDREN,
                QName.createQName("TestFolder" + GUID.generate()),
                ContentModel.TYPE_CONTENT)
            .getChildRef();

    // Apply permissions to folder
    permissionService.deletePermissions(folder);
    permissionService.setInheritParentPermissions(folder, false);
    permissionService.setPermission(folder, userName, permission, true);

    // Authenticate test user
    TestWithUserUtils.authenticateUser(
        this.userName, PWD, this.rootNodeRef, this.authenticationService);

    return folder;
  }
Example #25
0
 /*package*/ M2ModelDefinition(
     M2Model model, NamespacePrefixResolver resolver, DictionaryDAO dictionaryDAO) {
   this.name = QName.createQName(model.getName(), resolver);
   this.model = model;
   this.analyserResourceBundleName = model.getAnalyserResourceBundleName();
   this.dictionaryDAO = dictionaryDAO;
 }
Example #26
0
  @Override
  public IAfSysObject copyTo(String specific, String newName) throws AfException {
    if (isNew()) {
      throw new AfException("this object is new, you can not do copy action");
    }

    NodeService nodeService = ServiceHelper.getNodeService(afSession);
    NodeRef parent = getSpecifiedNode(specific);

    if (parent == null || !nodeService.exists(parent)) {
      throw new AfException("the folder " + specific + " you specified not exist");
    }

    IAfType folderType = AFCHelper.getNodeType(afSession, parent);
    if (!(folderType.isSubTypeOf("cm:folder") || folderType.getName().equals("cm:folder"))) {
      // parent is a doc
      throw new AfException("you can not copy object into a document");
    }

    CopyService copyService = ServiceHelper.getCopyService(afSession);

    String objName = (newName == null) ? getObjectName() : newName;
    QName nodeName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, objName);
    NodeRef ref = copyService.copyAndRename(nodeRef, parent, getAssType(), nodeName, true);

    IAfSysObject object = (IAfSysObject) afSession.getObject(new AfID(ref.getId()));

    object.setObjectName(objName);
    object.save();

    return object;
  }
Example #27
0
  @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;
  }
Example #28
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#startProperty(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
  */
 public void startProperty(NodeRef nodeRef, QName property) {
   try {
     contentHandler.startElement(
         property.getNamespaceURI(),
         property.getLocalName(),
         toPrefixString(property),
         EMPTY_ATTRIBUTES);
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process start property event - nodeRef "
             + nodeRef
             + "; property "
             + toPrefixString(property),
         e);
   }
 }
  /** Called at the begining of all tests */
  @Override
  protected void onSetUpInTransaction() throws Exception {
    this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");

    AuthenticationComponent authenticationComponent =
        (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());

    // Create the store and get the root node
    this.testStoreRef =
        this.nodeService.createStore(
            StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);

    // Create the node used for tests
    this.nodeRef =
        this.nodeService
            .createNode(
                this.rootNodeRef,
                ContentModel.ASSOC_CHILDREN,
                QName.createQName("{test}testnode"),
                ContentModel.TYPE_CONTENT)
            .getChildRef();

    // Get the executer instance
    this.executer =
        (AddFeaturesActionExecuter) this.applicationContext.getBean(AddFeaturesActionExecuter.NAME);
  }
  /**
   * Creates a directory to store the images in. The directory will be a sibling of the rendered
   * HTML, and named similar to it. Note this is only required if {@link #PARAM_IMAGES_SAME_FOLDER}
   * is false (the default).
   */
  private NodeRef createImagesDirectory(RenderingContext context) {
    // It should be a sibling of the HTML in it's eventual location
    //  (not it's current temporary one!)
    RenditionLocation location =
        resolveRenditionLocation(
            context.getSourceNode(), context.getDefinition(), context.getDestinationNode());
    NodeRef parent = location.getParentRef();

    // Figure out what to call it, based on the HTML node
    String folderName = getImagesDirectoryName(context);

    // It is already there?
    // (eg from when the rendition is being re-run)
    NodeRef imgFolder = nodeService.getChildByName(parent, ContentModel.ASSOC_CONTAINS, folderName);
    if (imgFolder != null) return imgFolder;

    // Create the directory
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    properties.put(ContentModel.PROP_NAME, folderName);
    imgFolder =
        nodeService
            .createNode(
                parent,
                ContentModel.ASSOC_CONTAINS,
                QName.createQName(folderName),
                ContentModel.TYPE_FOLDER,
                properties)
            .getChildRef();

    return imgFolder;
  }