Ejemplo n.º 1
0
  @Override
  public void unLink(String specific) throws AfException {

    if (isNew()) {
      throw new AfException("this object is new, you can not unlink it");
    }

    NodeService nodeService = ServiceHelper.getNodeService(afSession);

    NodeRef parent = getSpecifiedNode(specific);
    if (parent == null || !(nodeService.exists(parent))) {
      return;
    }

    List<ChildAssociationRef> parents = nodeService.getParentAssocs(nodeRef);

    for (ChildAssociationRef ref : parents) {

      if (ref.getParentRef().getId().equals(parent.getId())) {

        if (!ref.isPrimary()) {
          // not primary,delete
          nodeService.removeChildAssociation(ref);
          return;
        } else {
          // primary, it's not a good coding.f**k it!
          String rootId = AFCHelper.getNodeRefByPath(afSession, "/").getId();
          if (parents.size() <= 1) {
            if (rootId.equals(ref.getParentRef().getId())) {
              return;
            } else {
              moveTo("/", null);
              nodeService.removeChildAssociation(ref);
              return;
            }

          } else {
            // set the 2nd as the primary.moveTo
            for (ChildAssociationRef anotherP : parents) {
              if (!anotherP.equals(ref)) {
                String scndPId = anotherP.getParentRef().getId();

                nodeService.removeChildAssociation(anotherP);

                moveTo(scndPId, null);
                nodeService.removeChildAssociation(ref);
                return;
              }
            }
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
  /*
   * (non-Javadoc)
   * @see org.alfresco.cmis.property.PropertyAccessor#getValue(org.alfresco.service.cmr.repository.NodeRef)
   */
  public Serializable getValue(NodeRef nodeRef) {
    if (nodeRef.equals(getServiceRegistry().getCMISService().getDefaultRootNodeRef())) {
      return null;
    }

    ChildAssociationRef car = getServiceRegistry().getNodeService().getPrimaryParent(nodeRef);
    if ((car != null) && (car.getParentRef() != null)) {
      return car.getParentRef().toString();
    } else {
      return null;
    }
  }
  @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;
  }
  /**
   * @see
   *     org.alfresco.service.cmr.coci.CheckOutCheckInService#checkout(org.alfresco.service.cmr.repository.NodeRef)
   */
  public NodeRef checkout(NodeRef nodeRef) {
    // Find the primary parent in order to determine where to put the copy
    ChildAssociationRef childAssocRef = this.nodeService.getPrimaryParent(nodeRef);

    // Checkout the working copy to the same destination
    return checkout(
        nodeRef,
        childAssocRef.getParentRef(),
        childAssocRef.getTypeQName(),
        childAssocRef.getQName());
  }
Ejemplo n.º 5
0
  /* (non-Javadoc)
   * @see org.alfresco.repo.tenant.TenantService#getBaseName(org.alfresco.service.cmr.repository.ChildAssociationRef)
   */
  public ChildAssociationRef getBaseName(ChildAssociationRef childAssocRef) {
    if (childAssocRef == null) {
      return null;
    }

    return new ChildAssociationRef(
        childAssocRef.getTypeQName(),
        getBaseName(childAssocRef.getParentRef()),
        childAssocRef.getQName(),
        getBaseName(childAssocRef.getChildRef()),
        childAssocRef.isPrimary(),
        childAssocRef.getNthSibling());
  }
Ejemplo n.º 6
0
 /**
  * {@inheritDoc}
  *
  * <p>This method is thread-safe and lazily creates the required references, if required.
  */
 public ChildAssociationRef getChildAssocRef(QNameDAO qnameDAO) {
   boolean trashReference = false;
   // first check if it is available
   refReadLock.lock();
   try {
     if (childAssocRef != null) {
       // double check that the parent and child node references match those of our reference
       if (childAssocRef.getParentRef() != parent.getNodeRef()
           || childAssocRef.getChildRef() != child.getNodeRef()) {
         trashReference = true;
       } else {
         // we are sure that the reference is correct
         return childAssocRef;
       }
     }
   } finally {
     refReadLock.unlock();
   }
   // get write lock
   refWriteLock.lock();
   try {
     // double check
     if (childAssocRef == null || trashReference) {
       if (typeQName == null) {
         typeQName = qnameDAO.getQName(this.typeQNameId).getSecond();
       }
       if (qname == null) {
         String qnameNamespace = qnameDAO.getNamespace(qnameNamespaceId).getSecond();
         qname = QName.createQName(qnameNamespace, qnameLocalName);
       }
       childAssocRef =
           new ChildAssociationRef(
               typeQName, parent.getNodeRef(), qname, child.getNodeRef(), this.isPrimary, index);
     }
     return childAssocRef;
   } finally {
     refWriteLock.unlock();
   }
 }
Ejemplo n.º 7
0
  /**
   * Set auditable information and determine if auditing is required before method invocation. This
   * would normally be based on the method arguments.
   *
   * @param auditMode
   * @param auditInfo
   * @param mi
   * @return - the audit mode.
   */
  private AuditMode beforeInvocation(
      AuditMode auditMode, AuditState auditInfo, MethodInvocation mi) {
    AuditMode effectiveAuditMode = auditModel.beforeExecution(auditMode, mi);

    if (auditMode != AuditMode.NONE) {
      String methodName = mi.getMethod().getName();
      String serviceName = publicServiceIdentifier.getPublicServiceName(mi);
      auditInfo.setAuditApplication(SYSTEM_APPLICATION);
      auditInfo.setAuditConfiguration(auditConfiguration);
      auditInfo.setAuditMethod(methodName);
      auditInfo.setAuditService(serviceName);
      auditInfo.setClientAddress(null);
      auditInfo.setDate(new Date());
      auditInfo.setFail(false);
      auditInfo.setFiltered(false);
      auditInfo.setHostAddress(auditHost);

      auditInfo.setPath(null);

      Auditable auditable = mi.getMethod().getAnnotation(Auditable.class);
      Object key = null;
      switch (auditable.key()) {
        case ARG_0:
          checkArgLength(mi, methodName, serviceName, 0);
          key = mi.getArguments()[0];
          break;
        case ARG_1:
          checkArgLength(mi, methodName, serviceName, 1);
          key = mi.getArguments()[1];
          break;
        case ARG_2:
          checkArgLength(mi, methodName, serviceName, 2);
          key = mi.getArguments()[2];
          break;
        case ARG_3:
          checkArgLength(mi, methodName, serviceName, 3);
          key = mi.getArguments()[3];
          break;
        case ARG_4:
          checkArgLength(mi, methodName, serviceName, 4);
          key = mi.getArguments()[4];
          break;
        case ARG_5:
          checkArgLength(mi, methodName, serviceName, 5);
          key = mi.getArguments()[5];
          break;
        case ARG_6:
          checkArgLength(mi, methodName, serviceName, 6);
          key = mi.getArguments()[6];
          break;
        case ARG_7:
          checkArgLength(mi, methodName, serviceName, 7);
          key = mi.getArguments()[7];
          break;
        case ARG_8:
          checkArgLength(mi, methodName, serviceName, 8);
          key = mi.getArguments()[8];
          break;
        case ARG_9:
          checkArgLength(mi, methodName, serviceName, 9);
          key = mi.getArguments()[9];
          break;
        case NO_KEY:
        default:
          break;
      }
      if (key != null) {
        RecordOptions recordOptions = auditModel.getAuditRecordOptions(mi);
        if (key instanceof NodeRef) {
          auditInfo.setKeyStore(((NodeRef) key).getStoreRef());
          auditInfo.setKeyGUID(((NodeRef) key).getId());
          if (recordOptions != null && recordOptions.getRecordPath() == TrueFalseUnset.TRUE) {
            auditInfo.setPath(getNodePath((NodeRef) key));
          }
        } else if (key instanceof StoreRef) {
          auditInfo.setKeyStore((StoreRef) key);
        } else if (key instanceof ChildAssociationRef) {
          ChildAssociationRef car = (ChildAssociationRef) key;
          auditInfo.setKeyStore(car.getParentRef().getStoreRef());
          auditInfo.setKeyGUID(car.getParentRef().getId());
          if (recordOptions != null && recordOptions.getRecordPath() == TrueFalseUnset.TRUE) {
            auditInfo.setPath(getNodePath(car.getParentRef()));
          }
        } else if (key instanceof SearchParameters) {
          SearchParameters sp = (SearchParameters) key;
          if (sp.getStores().size() > 0) {
            auditInfo.setKeyStore(sp.getStores().get(0));
          }
        } else {
          logger.warn(
              "Key argument is not a node, store or child assoc reference or search parameters on "
                  + serviceName
                  + "."
                  + methodName
                  + " it is "
                  + key.getClass().getName());
        }
      }
      auditInfo.setKeyPropertiesAfter(null);
      auditInfo.setKeyPropertiesBefore(null);
      auditInfo.setMessage(null);
      if (mi.getArguments() != null) {
        Serializable[] serArgs = new Serializable[mi.getArguments().length];
        for (int i = 0; i < mi.getArguments().length; i++) {
          if ((auditable.recordable() == null)
              || (auditable.recordable().length <= i)
              || auditable.recordable()[i]) {
            if (mi.getArguments()[i] == null) {
              serArgs[i] = null;
            } else if (mi.getArguments()[i] instanceof Serializable) {
              serArgs[i] = (Serializable) mi.getArguments()[i];
            } else {
              serArgs[i] = mi.getArguments()[i].toString();
            }
          } else {
            serArgs[i] = "********";
          }
        }
        auditInfo.setMethodArguments(serArgs);
      }
      auditInfo.setReturnObject(null);
      auditInfo.setSessionId(null);
      auditInfo.setThrowable(null);
      auditInfo.setTxId(AlfrescoTransactionSupport.getTransactionId());
      auditInfo.setUserIdentifier(AuthenticationUtil.getFullyAuthenticatedUser());
    }

    return effectiveAuditMode;
  }