コード例 #1
0
      @Override
      public int compare(StoredObject f1, StoredObject f2) {
        String segment1 = f1.getName();
        String segment2 = f2.getName();

        return segment1.compareTo(segment2);
      }
コード例 #2
0
 @Override
 public void rename(StoredObject so, String newName, String user) {
   try {
     lock();
     if (so.getId().equals(fRootFolder.getId())) {
       throw new CmisInvalidArgumentException("Root folder cannot be renamed.");
     }
     if (so instanceof Fileable) {
       for (String folderId : ((Fileable) so).getParentIds()) {
         Folder folder = (Folder) getObjectById(folderId);
         if (hasChild(folder, newName)) {
           throw new CmisNameConstraintViolationException(
               "Cannot rename object to "
                   + newName
                   + ". This path already exists in parent "
                   + getFolderPath(folder.getId())
                   + ".");
         }
       }
     }
     so.setName(newName);
   } finally {
     unlock();
   }
 }
コード例 #3
0
  @Override
  public List<StoredObject> getRelationships(
      String objectId, List<String> typeIds, RelationshipDirection direction) {

    List<StoredObject> res = new ArrayList<StoredObject>();

    if (typeIds != null && typeIds.size() > 0) {
      for (String typeId : typeIds) {
        for (StoredObject so : fStoredObjectMap.values()) {
          if (so instanceof Relationship && so.getTypeId().equals(typeId)) {
            Relationship ro = (Relationship) so;
            if (ro.getSourceObjectId().equals(objectId)
                && (RelationshipDirection.EITHER == direction
                    || RelationshipDirection.SOURCE == direction)) {
              res.add(so);
            } else if (ro.getTargetObjectId().equals(objectId)
                && (RelationshipDirection.EITHER == direction
                    || RelationshipDirection.TARGET == direction)) {
              res.add(so);
            }
          }
        }
      }
    } else {
      res = getAllRelationships(objectId, direction);
    }
    return res;
  }
コード例 #4
0
  @Override
  public StoredObject createRelationship(
      String name,
      StoredObject sourceObject,
      StoredObject targetObject,
      Map<String, PropertyData<?>> propMap,
      String user,
      Acl addACEs,
      Acl removeACEs) {

    RelationshipImpl rel = new RelationshipImpl();
    rel.createSystemBasePropertiesWhenCreated(propMap, user);
    rel.setCustomProperties(propMap);
    rel.setRepositoryId(fRepositoryId);
    rel.setName(name);
    if (null != sourceObject) {
      rel.setSource(sourceObject.getId());
    }
    if (null != targetObject) {
      rel.setTarget(targetObject.getId());
    }
    String id = storeObject(rel);
    rel.setId(id);
    applyAcl(rel, addACEs, removeACEs);
    return rel;
  }
コード例 #5
0
 @Override
 public boolean isTypeInUse(String typeId) {
   // iterate over all the objects and check for each if the type matches
   for (String objectId : getIds()) {
     StoredObject so = getObjectById(objectId);
     if (so.getTypeId().equals(typeId)) {
       return true;
     }
   }
   return false;
 }
コード例 #6
0
 private void checkAccess(String principalId, StoredObject so, Permission permission) {
   if (!hasAccess(principalId, so, permission)) {
     throw new CmisPermissionDeniedException(
         "Object with id "
             + so.getId()
             + " and name "
             + so.getName()
             + " does not grant "
             + permission.toString()
             + " access to principal "
             + principalId);
   }
 }
コード例 #7
0
 public String storeObject(StoredObject so) {
   String id = so.getId();
   // check if update or create
   if (null == id) {
     id = getNextId().toString();
   }
   fStoredObjectMap.put(id, so);
   return id;
 }
コード例 #8
0
  @Override
  public void addParent(StoredObject so, Folder parent) {
    try {
      lock();
      if (hasChild(parent, so.getName())) {
        throw new IllegalArgumentException(
            "Cannot assign new parent folder, this name already exists in target folder.");
      }
      MultiFiling mfi;
      if (so instanceof MultiFiling) {
        mfi = (MultiFiling) so;
      } else {
        throw new IllegalArgumentException("Object " + so.getId() + "is not fileable");
      }

      addParentIntern(mfi, parent);
    } finally {
      unlock();
    }
  }
コード例 #9
0
  public Acl getAcl(
      CallContext context,
      String repositoryId,
      String objectId,
      Boolean onlyBasicPermissions,
      ExtensionsData extension,
      ObjectInfoHandler objectInfos) {
    LOG.debug("start getAcl()");
    Acl acl = null;
    StoredObject so = validator.getAcl(context, repositoryId, objectId, extension);
    if (so instanceof DocumentVersion) acl = ((DocumentVersion) so).getParentDocument().getAcl();
    else acl = so.getAcl();

    if (context.isObjectInfoRequired()) {
      ObjectInfoImpl objectInfo = new ObjectInfoImpl();
      fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfo);
      objectInfos.addObjectInfo(objectInfo);
    }

    return acl;
  }
コード例 #10
0
  @Override
  public void updateObject(
      StoredObject so, Map<String, PropertyData<?>> newProperties, String user) {
    // nothing to do
    Map<String, PropertyData<?>> properties = so.getProperties();
    for (String key : newProperties.keySet()) {
      PropertyData<?> value = newProperties.get(key);

      if (key.equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
        properties.put(key, value); // preserve it even if it is empty!
      } else if (null == value || value.getValues() == null || value.getFirstValue() == null) {
        // delete property
        properties.remove(key);
      } else {
        properties.put(key, value);
      }
    }
    // update system properties and secondary object type ids
    so.updateSystemBasePropertiesWhenModified(properties, user);
    properties.remove(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
  }
コード例 #11
0
  @Override
  public ContentStream setContent(StoredObject so, ContentStream contentStream) {
    if (so instanceof Content) {
      ContentStreamDataImpl newContent;
      Content content = (Content) so;

      if (null == contentStream) {
        newContent = null;
      } else {
        boolean useFakeContentStore =
            so.getTypeId().equals(DefaultTypeSystemCreator.BIG_CONTENT_FAKE_TYPE);
        newContent =
            new ContentStreamDataImpl(
                MAX_CONTENT_SIZE_KB == null ? 0 : MAX_CONTENT_SIZE_KB, useFakeContentStore);
        String fileName = contentStream.getFileName();
        if (null == fileName || fileName.length() <= 0) {
          fileName = so.getName(); // use name of document as fallback
        }
        newContent.setFileName(fileName);
        String mimeType = contentStream.getMimeType();
        if (null == mimeType || mimeType.length() <= 0) {
          mimeType = "application/octet-stream"; // use as fallback
        }
        newContent.setMimeType(mimeType);
        newContent.setLastModified(new GregorianCalendar());
        try {
          newContent.setContent(contentStream.getStream());
        } catch (IOException e) {
          throw new CmisRuntimeException("Failed to get content from InputStream", e);
        }
      }
      content.setContent(newContent);
      return newContent;

    } else {
      throw new CmisInvalidArgumentException(
          "Cannot set content, object does not implement interface Content.");
    }
  }
コード例 #12
0
 @Override
 public void move(StoredObject so, Folder oldParent, Folder newParent, String user) {
   try {
     if (hasChild(newParent, so.getName())) {
       throw new CmisInvalidArgumentException(
           "Cannot move object "
               + so.getName()
               + " to folder "
               + getFolderPath(newParent.getId())
               + ". A child with this name already exists.");
     }
     lock();
     if (so instanceof MultiFiling) {
       MultiFiling fi = (MultiFiling) so;
       addParentIntern(fi, newParent);
       removeParentIntern(fi, oldParent);
     } else if (so instanceof FolderImpl) {
       ((FolderImpl) so).setParentId(newParent.getId());
     }
   } finally {
     unlock();
   }
 }
コード例 #13
0
 @Override
 public List<String> getParentIds(StoredObject so, String user) {
   List<String> visibleParents = new ArrayList<String>();
   if (!(so instanceof Fileable)) {
     throw new CmisInvalidArgumentException("Object is not fileable: " + so.getId());
   }
   Filing fileable = (Fileable) so;
   List<String> parents = fileable.getParentIds();
   for (String id : parents) {
     StoredObject parent = getObjectById(id);
     if (hasReadAccess(user, parent)) {
       visibleParents.add(id);
     }
   }
   return visibleParents;
 }
コード例 #14
0
  @Override
  public void removeParent(StoredObject so, Folder parent) {
    try {
      lock();
      MultiFiling mfi;
      if (so instanceof MultiFiling) {
        mfi = (MultiFiling) so;
      } else {
        throw new IllegalArgumentException("Object " + so.getId() + "is not fileable");
      }

      removeParentIntern(mfi, parent);
    } finally {
      unlock();
    }
  }