예제 #1
0
 public User updateNewCollaborators(
     Collection collection,
     List<String> collaboratorsList,
     User apiCaller,
     String predicate,
     String collaboratorOperation) {
   List<User> userList = null;
   if (collaboratorsList != null && collaboratorsList.size() > 0 && !collaboratorsList.isEmpty()) {
     userList = this.getUserRepository().findByIdentities(collaboratorsList);
     if (collaboratorOperation.equals(DELETE)) {
       deleteCollaborators(collection, userList, apiCaller, predicate);
     } else {
       addNewCollaborators(collection, userList, apiCaller, predicate, false);
     }
   }
   if (userList.size() > 0) {
     User user = userList.get(0);
     user.setEmailId(user.getIdentities().iterator().next().getExternalId());
     return user;
   }
   return null;
 }
  @Override
  @Transactional(
      readOnly = false,
      propagation = Propagation.REQUIRED,
      rollbackFor = Exception.class)
  public ActionResponseDTO<Organization> saveOrganization(
      Organization organizationData, User user, HttpServletRequest request) {
    Errors errors = validateNullFields(organizationData);
    rejectIfMaxLimitExceed(400, organizationData.getPartyName(), GL0014, PARTY_NAME, "400");
    Organization newOrganization = new Organization();
    if (!errors.hasErrors()) {
      newOrganization.setPartyName(organizationData.getPartyName());
      String randomString = getRandomString(5);
      newOrganization.setOrganizationCode(randomString);
      newOrganization.setPartyType(PartyType.ORGANIZATION.getType());
      newOrganization.setCreatedOn(new Date(System.currentTimeMillis()));
      newOrganization.setS3StorageArea(storageRepository.getAvailableStorageArea(1));
      newOrganization.setNfsStorageArea(storageRepository.getAvailableStorageArea(2));
      newOrganization.setUserUid(user.getPartyUid());

      if (organizationData.getStateProvince() != null
          && organizationData.getStateProvince().getStateUid() != null) {
        newOrganization.setStateProvince(
            getCountryRepository().getState(organizationData.getStateProvince().getStateUid()));
      }
      if (organizationData.getType() != null && organizationData.getType().getValue() != null) {
        CustomTableValue type =
            this.getCustomTableRepository()
                .getCustomTableValue(
                    CustomProperties.Table.ORGANIZATION_CATEGORY.getTable(),
                    organizationData.getType().getValue());
        rejectIfNull(type, GL0056, TYPE);
        newOrganization.setType(type);
      }

      if (organizationData.getParentId() != null) {
        newOrganization.setParentOrganization(
            this.getOrganizationById(organizationData.getParentId()));
      }
      organizationRepository.save(newOrganization);
      updateOrgSetting(newOrganization);
      User newUser = new User();
      newUser.setOrganization(newOrganization);
      newUser.setFirstName(FIRST);
      newUser.setLastName(LAST);
      newUser.setPartyUid(ANONYMOUS_ + randomString);
      newUser.setUsername(ANONYMOUS_ + randomString);
      newUser.setEmailId(ANONYMOUS_ + randomString + AT_GMAIL_DOT_COM);
      Application application = new Application();
      application.setTitle(newOrganization.getPartyName());
      application.setUrl(HTTP_URL + newOrganization.getPartyName() + DOT_COM);
      try {
        User newOrgUser = new User();
        newOrgUser =
            userManagementService.createUser(
                newUser, null, null, 1, null, null, null, null, null, null, null, null, request,
                null, null);
        OrganizationSetting newOrganizationSetting = new OrganizationSetting();
        newOrganizationSetting.setOrganization(newOrganization);
        newOrganizationSetting.setKey(ANONYMOUS);
        newOrganizationSetting.setValue(newOrgUser.getPartyUid());
        organizationSettingRepository.save(newOrganizationSetting);
        application.setOrganization(newOrganization);
        applicationService.createApplication(application, newOrgUser);
        accountService.createSessionToken(newOrgUser, application.getKey(), request);

      } catch (Exception e) {
        LOGGER.debug("Error" + e);
      }
    }
    return new ActionResponseDTO<Organization>(newOrganization, errors);
  }