public void testUpdateExisting() throws Exception {
    long pk = nextLong();

    IGFolder newIGFolder = _persistence.create(pk);

    newIGFolder.setUuid(randomString());
    newIGFolder.setGroupId(nextLong());
    newIGFolder.setCompanyId(nextLong());
    newIGFolder.setUserId(nextLong());
    newIGFolder.setCreateDate(nextDate());
    newIGFolder.setModifiedDate(nextDate());
    newIGFolder.setParentFolderId(nextLong());
    newIGFolder.setName(randomString());
    newIGFolder.setDescription(randomString());

    _persistence.update(newIGFolder, false);

    IGFolder existingIGFolder = _persistence.findByPrimaryKey(newIGFolder.getPrimaryKey());

    assertEquals(existingIGFolder.getUuid(), newIGFolder.getUuid());
    assertEquals(existingIGFolder.getFolderId(), newIGFolder.getFolderId());
    assertEquals(existingIGFolder.getGroupId(), newIGFolder.getGroupId());
    assertEquals(existingIGFolder.getCompanyId(), newIGFolder.getCompanyId());
    assertEquals(existingIGFolder.getUserId(), newIGFolder.getUserId());
    assertEquals(
        Time.getShortTimestamp(existingIGFolder.getCreateDate()),
        Time.getShortTimestamp(newIGFolder.getCreateDate()));
    assertEquals(
        Time.getShortTimestamp(existingIGFolder.getModifiedDate()),
        Time.getShortTimestamp(newIGFolder.getModifiedDate()));
    assertEquals(existingIGFolder.getParentFolderId(), newIGFolder.getParentFolderId());
    assertEquals(existingIGFolder.getName(), newIGFolder.getName());
    assertEquals(existingIGFolder.getDescription(), newIGFolder.getDescription());
  }
Пример #2
0
  public Resource getResource(WebDAVRequest webDavRequest) throws WebDAVException {

    try {
      String[] pathArray = webDavRequest.getPathArray();

      long companyId = webDavRequest.getCompanyId();
      long parentFolderId = getParentFolderId(companyId, pathArray);
      String name = WebDAVUtil.getResourceName(pathArray);

      if (Validator.isNull(name)) {
        String path = getRootPath() + webDavRequest.getPath();

        return new BaseResourceImpl(path, StringPool.BLANK, getToken());
      }

      try {
        IGFolder folder =
            IGFolderServiceUtil.getFolder(webDavRequest.getGroupId(), parentFolderId, name);

        if ((folder.getParentFolderId() != parentFolderId)
            || (webDavRequest.getGroupId() != folder.getGroupId())) {

          throw new NoSuchFolderException();
        }

        return toResource(webDavRequest, folder, false);
      } catch (NoSuchFolderException nsfe) {
        try {
          long groupId = webDavRequest.getGroupId();

          IGImage image =
              IGImageServiceUtil.getImageByFolderIdAndNameWithExtension(
                  groupId, parentFolderId, name);

          return toResource(webDavRequest, image, false);
        } catch (NoSuchImageException nsie) {
          return null;
        }
      }
    } catch (Exception e) {
      throw new WebDAVException(e);
    }
  }