@Override
  public SyncDLObject addFolder(
      long repositoryId,
      long parentFolderId,
      String name,
      String description,
      ServiceContext serviceContext)
      throws PortalException {

    try {
      Group group = groupLocalService.getGroup(repositoryId);

      SyncUtil.checkSyncEnabled(group.getGroupId());

      if (!group.isUser() && (serviceContext.getGroupPermissions() == null)) {

        SyncUtil.setFilePermissions(group, true, serviceContext);
      }

      Folder folder =
          dlAppService.addFolder(repositoryId, parentFolderId, name, description, serviceContext);

      return toSyncDLObject(folder, SyncConstants.EVENT_ADD);
    } catch (PortalException pe) {
      if (pe instanceof DuplicateFolderNameException) {
        if (GetterUtil.getBoolean(serviceContext.getAttribute("overwrite"))) {

          Folder folder = dlAppService.getFolder(repositoryId, parentFolderId, name);

          folder =
              dlAppService.updateFolder(folder.getFolderId(), name, description, serviceContext);

          return toSyncDLObject(folder, SyncConstants.EVENT_UPDATE);
        }
      }

      throw new PortalException(SyncUtil.buildExceptionMessage(pe), pe);
    }
  }
  @Override
  public SyncDLObject addFileEntry(
      long repositoryId,
      long folderId,
      String sourceFileName,
      String mimeType,
      String title,
      String description,
      String changeLog,
      File file,
      String checksum,
      ServiceContext serviceContext)
      throws PortalException {

    try {
      Group group = groupLocalService.getGroup(repositoryId);

      SyncUtil.checkSyncEnabled(group.getGroupId());

      if (!group.isUser() && (serviceContext.getGroupPermissions() == null)) {

        SyncUtil.setFilePermissions(group, false, serviceContext);
      }

      FileEntry fileEntry =
          dlAppService.addFileEntry(
              repositoryId,
              folderId,
              sourceFileName,
              mimeType,
              title,
              description,
              changeLog,
              file,
              serviceContext);

      return toSyncDLObject(fileEntry, SyncConstants.EVENT_ADD);
    } catch (PortalException pe) {
      if (pe instanceof DuplicateFileException) {
        if (GetterUtil.getBoolean(serviceContext.getAttribute("overwrite"))) {

          FileEntry fileEntry = dlAppService.getFileEntry(repositoryId, folderId, title);

          fileEntry =
              dlAppService.updateFileEntry(
                  fileEntry.getFileEntryId(),
                  sourceFileName,
                  mimeType,
                  title,
                  description,
                  changeLog,
                  false,
                  file,
                  serviceContext);

          return toSyncDLObject(fileEntry, SyncConstants.EVENT_UPDATE);
        }
      }

      throw new PortalException(SyncUtil.buildExceptionMessage(pe), pe);
    }
  }