private void updateOrgSetting(Organization newOrganization) { OrganizationSetting newOrganizationSetting = new OrganizationSetting(); newOrganizationSetting.setOrganization(newOrganization); newOrganizationSetting.setKey(ConfigConstants.ACCESS_GOORU_CONTENT); newOrganizationSetting.setValue("1"); organizationSettingRepository.save(newOrganizationSetting); }
@Override public ActionResponseDTO<OrganizationSetting> saveOrUpdateOrganizationSetting( String organizationUid, OrganizationSetting organizationSetting) throws Exception { boolean isUpdateOrInsertDone = false; if (organizationUid != null && organizationSetting != null && organizationSetting.getValue() != null) { OrganizationSetting existingOrganizationSetting = organizationSettingRepository.getOrganizationSettings( organizationUid, organizationSetting.getKey()); if (existingOrganizationSetting == null) { OrganizationSetting newOrganizationSetting = new OrganizationSetting(); newOrganizationSetting.setOrganization( organizationRepository.getOrganizationByUid(organizationUid)); newOrganizationSetting.setKey(organizationSetting.getKey()); newOrganizationSetting.setValue(organizationSetting.getValue()); organizationSettingRepository.save(newOrganizationSetting); isUpdateOrInsertDone = true; } else { if (existingOrganizationSetting != null) { existingOrganizationSetting.setValue(organizationSetting.getValue()); organizationSetting.setOrganization( organizationRepository.getOrganizationByUid(organizationUid)); organizationSettingRepository.save(existingOrganizationSetting); organizationSetting = existingOrganizationSetting; isUpdateOrInsertDone = true; } } if (isUpdateOrInsertDone) { settingService.resetOrganizationSettings(organizationSetting.getKey()); } } else { throw new BadRequestException("Values should not be null !"); } return new ActionResponseDTO<OrganizationSetting>(organizationSetting, 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); }