@Override
  public int compareTo(SyncDLObject syncDLObject) {
    int value = 0;

    if (getModifiedTime() < syncDLObject.getModifiedTime()) {
      value = -1;
    } else if (getModifiedTime() > syncDLObject.getModifiedTime()) {
      value = 1;
    } else {
      value = 0;
    }

    if (value != 0) {
      return value;
    }

    if (getRepositoryId() < syncDLObject.getRepositoryId()) {
      value = -1;
    } else if (getRepositoryId() > syncDLObject.getRepositoryId()) {
      value = 1;
    } else {
      value = 0;
    }

    if (value != 0) {
      return value;
    }

    return 0;
  }
  protected List<SyncDLObject> getSyncDLObjects(
      List<SyncDLObject> syncDLObjects,
      long companyId,
      long repositoryId,
      long parentFolderId,
      long lastAccessTime)
      throws PortalException {

    List<SyncDLObject> curSyncDLObjects =
        syncDLObjectFinder.filterFindByC_M_R_P(
            companyId, lastAccessTime, repositoryId, parentFolderId);

    if (!InlineSQLHelperUtil.isEnabled(repositoryId)) {
      curSyncDLObjects = checkSyncDLObjects(curSyncDLObjects);
    }

    syncDLObjects.addAll(curSyncDLObjects);

    for (SyncDLObject curSyncDLObject : curSyncDLObjects) {
      String type = curSyncDLObject.getType();

      if (!type.equals(SyncConstants.TYPE_FOLDER)) {
        continue;
      }

      getSyncDLObjects(
          syncDLObjects, companyId, repositoryId, curSyncDLObject.getTypePK(), lastAccessTime);
    }

    return syncDLObjects;
  }
  @Override
  public SyncDLObjectUpdate getSyncDLObjectUpdate(
      long companyId, long repositoryId, long lastAccessTime) throws PortalException {

    try {
      SyncUtil.checkSyncEnabled(repositoryId);

      repositoryService.checkRepository(repositoryId);

      List<SyncDLObject> syncDLObjects =
          syncDLObjectFinder.filterFindByC_M_R_P(companyId, lastAccessTime, repositoryId, -1);

      if (!InlineSQLHelperUtil.isEnabled(repositoryId)) {
        syncDLObjects = checkSyncDLObjects(syncDLObjects);
      }

      for (SyncDLObject syncDLObject : syncDLObjects) {
        if (syncDLObject.getModifiedTime() > lastAccessTime) {
          lastAccessTime = syncDLObject.getModifiedTime();
        }
      }

      return new SyncDLObjectUpdate(syncDLObjects, lastAccessTime);
    } catch (PortalException pe) {
      throw new PortalException(SyncUtil.buildExceptionMessage(pe), pe);
    }
  }
  /**
   * Adds the sync d l object to the database. Also notifies the appropriate model listeners.
   *
   * @param syncDLObject the sync d l object
   * @return the sync d l object that was added
   * @throws SystemException if a system exception occurred
   */
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public SyncDLObject addSyncDLObject(SyncDLObject syncDLObject) throws SystemException {
    syncDLObject.setNew(true);

    return syncDLObjectPersistence.update(syncDLObject);
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    if (!(obj instanceof SyncDLObject)) {
      return false;
    }

    SyncDLObject syncDLObject = (SyncDLObject) obj;

    long primaryKey = syncDLObject.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  protected List<SyncDLObject> checkSyncDLObjects(List<SyncDLObject> syncDLObjects) {

    Iterator<SyncDLObject> iterator = syncDLObjects.iterator();

    while (iterator.hasNext()) {
      SyncDLObject syncDLObject = iterator.next();

      String type = syncDLObject.getType();

      try {
        if (type.equals(SyncConstants.TYPE_FILE)
            || type.equals(SyncConstants.TYPE_PRIVATE_WORKING_COPY)) {

          dlAppService.getFileEntry(syncDLObject.getTypePK());
        } else {
          dlAppService.getFolder(syncDLObject.getTypePK());
        }
      } catch (Exception e) {
        iterator.remove();
      }
    }

    return syncDLObjects;
  }
  protected SyncDLObject checkModifiedTime(SyncDLObject syncDLObject, long typePk) {

    DynamicQuery dynamicQuery = DLSyncEventLocalServiceUtil.dynamicQuery();

    dynamicQuery.add(RestrictionsFactoryUtil.eq("typePK", typePk));

    List<DLSyncEvent> dlSyncEvents = DLSyncEventLocalServiceUtil.dynamicQuery(dynamicQuery);

    if (dlSyncEvents.isEmpty()) {
      return syncDLObject;
    }

    DLSyncEvent dlSyncEvent = dlSyncEvents.get(0);

    syncDLObject.setModifiedTime(dlSyncEvent.getModifiedTime());

    return syncDLObject;
  }
  @Override
  public void moveSyncDLObjects(final SyncDLObject parentSyncDLObject) throws PortalException {

    final String searchTreePath =
        StringUtil.quote(String.valueOf(parentSyncDLObject.getTypePK()), StringPool.SLASH);

    ActionableDynamicQuery actionableDynamicQuery = getActionableDynamicQuery();

    actionableDynamicQuery.setAddCriteriaMethod(
        new ActionableDynamicQuery.AddCriteriaMethod() {

          @Override
          public void addCriteria(DynamicQuery dynamicQuery) {
            dynamicQuery.add(
                RestrictionsFactoryUtil.like(
                    "treePath", StringUtil.quote(searchTreePath, StringPool.PERCENT)));
          }
        });
    actionableDynamicQuery.setPerformActionMethod(
        new ActionableDynamicQuery.PerformActionMethod<SyncDLObject>() {

          @Override
          public void performAction(SyncDLObject syncDLObject) throws PortalException {

            syncDLObject.setUserId(parentSyncDLObject.getUserId());
            syncDLObject.setUserName(parentSyncDLObject.getUserName());

            String treePath = syncDLObject.getTreePath();

            String oldParentTreePath =
                treePath.substring(0, treePath.indexOf(searchTreePath) + searchTreePath.length());

            treePath =
                StringUtil.replaceFirst(
                    treePath, oldParentTreePath, parentSyncDLObject.getTreePath());

            syncDLObject.setTreePath(treePath);

            syncDLObjectPersistence.update(syncDLObject);
          }
        });

    actionableDynamicQuery.performActions();
  }
  @Override
  public SyncDLObject addSyncDLObject(
      long companyId,
      long userId,
      String userName,
      long modifiedTime,
      long repositoryId,
      long parentFolderId,
      String treePath,
      String name,
      String extension,
      String mimeType,
      String description,
      String changeLog,
      String extraSettings,
      String version,
      long versionId,
      long size,
      String checksum,
      String event,
      Date lockExpirationDate,
      long lockUserId,
      String lockUserName,
      String type,
      long typePK,
      String typeUuid)
      throws PortalException {

    if (!isDefaultRepository(parentFolderId)) {
      return null;
    }

    SyncDLObject syncDLObject = syncDLObjectPersistence.fetchByT_T(type, typePK);

    if (syncDLObject == null) {
      long syncDLObjectId = counterLocalService.increment();

      syncDLObject = syncDLObjectPersistence.create(syncDLObjectId);

      syncDLObject.setCompanyId(companyId);
      syncDLObject.setCreateTime(modifiedTime);
      syncDLObject.setRepositoryId(repositoryId);
      syncDLObject.setType(type);
      syncDLObject.setTypePK(typePK);
      syncDLObject.setTypeUuid(typeUuid);

      if (type.equals(SyncDLObjectConstants.TYPE_PRIVATE_WORKING_COPY)) {
        SyncDLObject approvedSyncDLObject =
            syncDLObjectPersistence.fetchByT_T(SyncDLObjectConstants.TYPE_FILE, typePK);

        approvedSyncDLObject.setModifiedTime(modifiedTime);
        approvedSyncDLObject.setLockExpirationDate(lockExpirationDate);
        approvedSyncDLObject.setLockUserId(lockUserId);
        approvedSyncDLObject.setLockUserName(lockUserName);

        syncDLObjectPersistence.update(approvedSyncDLObject);
      }
    } else if (syncDLObject.getModifiedTime() >= modifiedTime) {
      return null;
    } else if (type.equals(SyncDLObjectConstants.TYPE_FILE)) {
      SyncDLObject pwcSyncDLObject =
          syncDLObjectPersistence.fetchByT_T(
              SyncDLObjectConstants.TYPE_PRIVATE_WORKING_COPY, typePK);

      if (pwcSyncDLObject != null) {
        DLFileEntry dlFileEntry = dlFileEntryLocalService.fetchDLFileEntry(typePK);

        if ((dlFileEntry == null) || !dlFileEntry.isCheckedOut()) {
          syncDLObjectPersistence.remove(pwcSyncDLObject);
        }
      }
    } else if (type.equals(SyncDLObjectConstants.TYPE_PRIVATE_WORKING_COPY)) {
      if (event.equals(SyncDLObjectConstants.EVENT_RESTORE)
          || event.equals(SyncDLObjectConstants.EVENT_TRASH)) {

        SyncDLObject approvedSyncDLObject =
            syncDLObjectPersistence.fetchByT_T(SyncDLObjectConstants.TYPE_FILE, typePK);

        approvedSyncDLObject.setEvent(event);

        syncDLObjectPersistence.update(approvedSyncDLObject);
      }
    }

    syncDLObject.setUserId(userId);
    syncDLObject.setUserName(userName);
    syncDLObject.setModifiedTime(modifiedTime);
    syncDLObject.setParentFolderId(parentFolderId);
    syncDLObject.setTreePath(treePath);
    syncDLObject.setName(name);
    syncDLObject.setExtension(extension);
    syncDLObject.setMimeType(mimeType);
    syncDLObject.setDescription(description);
    syncDLObject.setChangeLog(changeLog);
    syncDLObject.setVersion(version);
    syncDLObject.setVersionId(versionId);
    syncDLObject.setSize(size);
    syncDLObject.setChecksum(checksum);
    syncDLObject.setEvent(event);
    syncDLObject.setLockExpirationDate(lockExpirationDate);
    syncDLObject.setLockUserId(lockUserId);
    syncDLObject.setLockUserName(lockUserName);

    syncDLObject = syncDLObjectPersistence.update(syncDLObject);

    if (type.equals(SyncDLObjectConstants.TYPE_FILE)
        && ArrayUtil.contains(
            PortletPropsValues.SYNC_MAC_PACKAGE_METADATA_FILE_NAMES, syncDLObject.getName())) {

      SyncDLObject parentFolderSyncDLObject =
          syncDLObjectPersistence.fetchByT_T(
              SyncDLObjectConstants.TYPE_FOLDER, syncDLObject.getParentFolderId());

      String parentFolderExtension = FileUtil.getExtension(parentFolderSyncDLObject.getName());

      if (ArrayUtil.contains(
          PortletPropsValues.SYNC_MAC_PACKAGE_FOLDER_EXTENSIONS, parentFolderExtension)) {

        JSONObject extraSettingsJSONObject =
            JSONFactoryUtil.createJSONObject(parentFolderSyncDLObject.getExtraSettings());

        extraSettingsJSONObject.put("macPackage", true);

        parentFolderSyncDLObject.setExtraSettings(extraSettingsJSONObject.toString());

        syncDLObjectPersistence.update(parentFolderSyncDLObject);
      }
    }

    if (type.equals(SyncDLObjectConstants.TYPE_FOLDER)) {
      if (Validator.isNull(treePath)) {
        return syncDLObject;
      }

      if (event.equals(SyncDLObjectConstants.EVENT_MOVE)) {
        moveSyncDLObjects(syncDLObject);
      } else if (event.equals(SyncDLObjectConstants.EVENT_RESTORE)) {
        restoreSyncDLObjects(syncDLObject);
      } else if (event.equals(SyncDLObjectConstants.EVENT_TRASH)) {
        trashSyncDLObjects(syncDLObject);
      }
    } else if (event.equals(SyncDLObjectConstants.EVENT_DELETE)) {
      try {
        syncDLFileVersionDiffLocalService.deleteSyncDLFileVersionDiffs(typePK);
      } catch (Exception e) {
        _log.error(e, e);
      }
    }

    return syncDLObject;
  }
  @Override
  public SyncDLObject patchFileEntry(
      long fileEntryId,
      long sourceVersionId,
      String sourceFileName,
      String mimeType,
      String title,
      String description,
      String changeLog,
      boolean majorVersion,
      File deltaFile,
      String checksum,
      ServiceContext serviceContext)
      throws PortalException {

    File patchedFile = null;

    try {
      FileEntry fileEntry = dlAppLocalService.getFileEntry(fileEntryId);

      SyncUtil.checkSyncEnabled(fileEntry.getGroupId());

      DLFileVersion dlFileVersion = dlFileVersionLocalService.getDLFileVersion(sourceVersionId);

      File sourceFile =
          dlFileEntryLocalService.getFile(fileEntryId, dlFileVersion.getVersion(), false);

      patchedFile = FileUtil.createTempFile();

      SyncUtil.patchFile(sourceFile, deltaFile, patchedFile);

      SyncDLObject syncDLObject =
          updateFileEntry(
              fileEntryId,
              sourceFileName,
              mimeType,
              title,
              description,
              changeLog,
              majorVersion,
              patchedFile,
              checksum,
              serviceContext);

      if (PortletPropsValues.SYNC_FILE_DIFF_CACHE_ENABLED
          && (sourceVersionId != syncDLObject.getVersionId())) {

        DLFileVersion targetDLFileVersion =
            dlFileVersionLocalService.getFileVersion(syncDLObject.getVersionId());

        syncDLFileVersionDiffLocalService.addSyncDLFileVersionDiff(
            fileEntryId, sourceVersionId, targetDLFileVersion.getFileVersionId(), deltaFile);
      }

      return syncDLObject;
    } catch (PortalException pe) {
      throw new PortalException(SyncUtil.buildExceptionMessage(pe), pe);
    } finally {
      FileUtil.delete(patchedFile);
    }
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static SyncDLObject toModel(SyncDLObjectSoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    SyncDLObject model = new SyncDLObjectImpl();

    model.setSyncDLObjectId(soapModel.getSyncDLObjectId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateTime(soapModel.getCreateTime());
    model.setModifiedTime(soapModel.getModifiedTime());
    model.setRepositoryId(soapModel.getRepositoryId());
    model.setParentFolderId(soapModel.getParentFolderId());
    model.setTreePath(soapModel.getTreePath());
    model.setName(soapModel.getName());
    model.setExtension(soapModel.getExtension());
    model.setMimeType(soapModel.getMimeType());
    model.setDescription(soapModel.getDescription());
    model.setChangeLog(soapModel.getChangeLog());
    model.setExtraSettings(soapModel.getExtraSettings());
    model.setVersion(soapModel.getVersion());
    model.setVersionId(soapModel.getVersionId());
    model.setSize(soapModel.getSize());
    model.setChecksum(soapModel.getChecksum());
    model.setEvent(soapModel.getEvent());
    model.setLanTokenKey(soapModel.getLanTokenKey());
    model.setLastPermissionChangeDate(soapModel.getLastPermissionChangeDate());
    model.setLockExpirationDate(soapModel.getLockExpirationDate());
    model.setLockUserId(soapModel.getLockUserId());
    model.setLockUserName(soapModel.getLockUserName());
    model.setType(soapModel.getType());
    model.setTypePK(soapModel.getTypePK());
    model.setTypeUuid(soapModel.getTypeUuid());

    return model;
  }
Exemplo n.º 12
0
  public static SyncDLObject toSyncDLObject(DLFolder dlFolder, String event) {
    SyncDLObject syncDLObject = new SyncDLObjectImpl();

    syncDLObject.setCompanyId(dlFolder.getCompanyId());
    syncDLObject.setCreateDate(dlFolder.getCreateDate());
    syncDLObject.setModifiedDate(dlFolder.getModifiedDate());
    syncDLObject.setRepositoryId(dlFolder.getRepositoryId());
    syncDLObject.setParentFolderId(dlFolder.getParentFolderId());
    syncDLObject.setName(dlFolder.getName());
    syncDLObject.setExtension(StringPool.BLANK);
    syncDLObject.setMimeType(StringPool.BLANK);
    syncDLObject.setDescription(dlFolder.getDescription());
    syncDLObject.setChangeLog(StringPool.BLANK);
    syncDLObject.setExtraSettings(StringPool.BLANK);
    syncDLObject.setVersion(StringPool.BLANK);
    syncDLObject.setSize(0);
    syncDLObject.setChecksum(StringPool.BLANK);
    syncDLObject.setEvent(event);
    syncDLObject.setLockExpirationDate(null);
    syncDLObject.setLockUserId(0);
    syncDLObject.setLockUserName(StringPool.BLANK);
    syncDLObject.setType(SyncConstants.TYPE_FOLDER);
    syncDLObject.setTypePK(dlFolder.getFolderId());
    syncDLObject.setTypeUuid(dlFolder.getUuid());

    return syncDLObject;
  }
Exemplo n.º 13
0
  public static SyncDLObject toSyncDLObject(
      DLFileEntry dlFileEntry, String event, boolean excludeWorkingCopy)
      throws PortalException, SystemException {

    DLFileVersion dlFileVersion = null;

    Date lockExpirationDate = null;
    long lockUserId = 0;
    String lockUserName = StringPool.BLANK;
    String type = null;

    Lock lock = dlFileEntry.getLock();

    if ((lock == null) || excludeWorkingCopy) {
      dlFileVersion =
          DLFileVersionLocalServiceUtil.getFileVersion(
              dlFileEntry.getFileEntryId(), dlFileEntry.getVersion());

      type = SyncConstants.TYPE_FILE;
    } else {
      dlFileVersion =
          DLFileVersionLocalServiceUtil.getFileVersion(
              dlFileEntry.getFileEntryId(), DLFileEntryConstants.PRIVATE_WORKING_COPY_VERSION);

      lockExpirationDate = lock.getExpirationDate();
      lockUserId = lock.getUserId();
      lockUserName = lock.getUserName();
      type = SyncConstants.TYPE_PRIVATE_WORKING_COPY;
    }

    SyncDLObject syncDLObject = new SyncDLObjectImpl();

    syncDLObject.setCompanyId(dlFileVersion.getCompanyId());
    syncDLObject.setCreateDate(dlFileVersion.getCreateDate());
    syncDLObject.setModifiedDate(dlFileVersion.getModifiedDate());
    syncDLObject.setRepositoryId(dlFileVersion.getRepositoryId());
    syncDLObject.setParentFolderId(dlFileVersion.getFolderId());
    syncDLObject.setName(dlFileVersion.getTitle());
    syncDLObject.setExtension(dlFileVersion.getExtension());
    syncDLObject.setMimeType(dlFileVersion.getMimeType());
    syncDLObject.setDescription(dlFileVersion.getDescription());
    syncDLObject.setChangeLog(dlFileVersion.getChangeLog());
    syncDLObject.setExtraSettings(dlFileVersion.getExtraSettings());
    syncDLObject.setVersion(dlFileVersion.getVersion());
    syncDLObject.setSize(dlFileVersion.getSize());
    syncDLObject.setChecksum(getChecksum(dlFileVersion));
    syncDLObject.setEvent(event);
    syncDLObject.setLockExpirationDate(lockExpirationDate);
    syncDLObject.setLockUserId(lockUserId);
    syncDLObject.setLockUserName(lockUserName);
    syncDLObject.setType(type);
    syncDLObject.setTypePK(dlFileEntry.getFileEntryId());
    syncDLObject.setTypeUuid(dlFileEntry.getUuid());

    return syncDLObject;
  }