Exemple #1
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;
  }
Exemple #2
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;
  }