@Override public UcdProcessDTO create(UcdProcessDTO dto) throws EntityCreationException, EntityRetrievalException { UcdProcessEntity entity = null; try { if (dto.getId() != null) { entity = this.getEntityById(dto.getId()); } } catch (EntityRetrievalException e) { throw new EntityCreationException(e); } if (entity != null) { throw new EntityCreationException("An entity with this ID already exists."); } else { entity = new UcdProcessEntity(); entity.setCreationDate(new Date()); entity.setDeleted(false); entity.setLastModifiedDate(new Date()); entity.setLastModifiedUser(Util.getCurrentUser().getId()); entity.setName(dto.getName()); create(entity); return new UcdProcessDTO(entity); } }
@Override public void create(CQMResultDTO cqmResult) throws EntityCreationException { CQMResultEntity entity = null; try { if (cqmResult.getId() != null) { entity = this.getEntityById(cqmResult.getId()); } } catch (EntityRetrievalException e) { throw new EntityCreationException(e); } if (entity != null) { throw new EntityCreationException("An entity with this ID already exists."); } else { entity = new CQMResultEntity(); entity.setCqmCriterionId(cqmResult.getCqmCriterionId()); entity.setCertifiedProductId(cqmResult.getCertifiedProductId()); entity.setSuccess(cqmResult.getSuccess()); entity.setLastModifiedUser(Util.getCurrentUser().getId()); entity.setLastModifiedDate(new Date()); entity.setCreationDate(cqmResult.getCreationDate()); entity.setDeleted(false); create(entity); } }
@Override public String refreshJWT() throws JWTCreationException { User user = Util.getCurrentUser(); String jwt = null; if (user != null) { Map<String, List<String>> claims = new HashMap<String, List<String>>(); List<String> claimStrings = new ArrayList<String>(); Set<GrantedPermission> permissions = user.getPermissions(); for (GrantedPermission claim : permissions) { claimStrings.add(claim.getAuthority()); } claims.put("Authorities", claimStrings); List<String> identity = new ArrayList<String>(); identity.add(user.getId().toString()); identity.add(user.getName()); identity.add(user.getFirstName()); identity.add(user.getLastName()); claims.put("Identity", identity); jwt = jwtAuthor.createJWT(user.getSubjectName(), claims); } else { throw new JWTCreationException("Cannot generate token for Anonymous user."); } return jwt; }
@Override @Transactional public TestingLabDTO create(TestingLabDTO dto) throws EntityCreationException, EntityRetrievalException { TestingLabEntity entity = null; try { if (dto.getId() != null) { entity = this.getEntityById(dto.getId()); } } catch (EntityRetrievalException e) { throw new EntityCreationException(e); } if (entity != null) { throw new EntityCreationException("An entity with this ID already exists."); } else { entity = new TestingLabEntity(); if (dto.getAddress() != null) { entity.setAddress(addressDao.mergeAddress(dto.getAddress())); } entity.setName(dto.getName()); entity.setWebsite(dto.getWebsite()); entity.setAccredidationNumber(dto.getAccredidationNumber()); entity.setTestingLabCode(dto.getTestingLabCode()); if (dto.getDeleted() != null) { entity.setDeleted(dto.getDeleted()); } else { entity.setDeleted(false); } if (dto.getLastModifiedUser() != null) { entity.setLastModifiedUser(dto.getLastModifiedUser()); } else { entity.setLastModifiedUser(Util.getCurrentUser().getId()); } if (dto.getLastModifiedDate() != null) { entity.setLastModifiedDate(dto.getLastModifiedDate()); } else { entity.setLastModifiedDate(new Date()); } if (dto.getCreationDate() != null) { entity.setCreationDate(dto.getCreationDate()); } else { entity.setCreationDate(new Date()); } create(entity); return new TestingLabDTO(entity); } }
@Override public void delete(Long id) throws EntityRetrievalException { UcdProcessEntity toDelete = getEntityById(id); if (toDelete != null) { toDelete.setDeleted(true); toDelete.setLastModifiedDate(new Date()); toDelete.setLastModifiedUser(Util.getCurrentUser().getId()); update(toDelete); } }
@Override @Transactional public TestingLabDTO update(TestingLabDTO dto) throws EntityRetrievalException { TestingLabEntity entity = this.getEntityById(dto.getId()); if (entity == null) { throw new EntityRetrievalException("Entity with id " + dto.getId() + " does not exist"); } if (dto.getAddress() != null) { try { entity.setAddress(addressDao.mergeAddress(dto.getAddress())); } catch (EntityCreationException ex) { logger.error("Could not create new address in the database.", ex); entity.setAddress(null); } } else { entity.setAddress(null); } entity.setWebsite(dto.getWebsite()); entity.setAccredidationNumber(dto.getAccredidationNumber()); if (dto.getName() != null) { entity.setName(dto.getName()); } if (dto.getTestingLabCode() != null) { entity.setTestingLabCode(dto.getTestingLabCode()); } if (dto.getDeleted() != null) { entity.setDeleted(dto.getDeleted()); } if (dto.getLastModifiedUser() != null) { entity.setLastModifiedUser(dto.getLastModifiedUser()); } else { entity.setLastModifiedUser(Util.getCurrentUser().getId()); } if (dto.getLastModifiedDate() != null) { entity.setLastModifiedDate(dto.getLastModifiedDate()); } else { entity.setLastModifiedDate(new Date()); } update(entity); return new TestingLabDTO(entity); }
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_ACB_ADMIN') or hasRole('ROLE_ACB_STAFF')") @Transactional(readOnly = false) public VendorDTO update(VendorDTO vendor) throws EntityRetrievalException, JsonProcessingException, EntityCreationException { VendorDTO before = getById(vendor.getId()); VendorEntity result = vendorDao.update(vendor); // chplAdmin cannot update the transparency but any other role // allowed in this method can boolean isChplAdmin = false; Set<GrantedPermission> permissions = Util.getCurrentUser().getPermissions(); for (GrantedPermission permission : permissions) { if (permission.getAuthority().equals("ROLE_ADMIN")) { isChplAdmin = true; } } if (!isChplAdmin) { List<CertificationBodyDTO> availableAcbs = acbManager.getAllForUser(); if (availableAcbs != null && availableAcbs.size() > 0) { for (CertificationBodyDTO acb : availableAcbs) { VendorACBMapDTO existingMap = vendorDao.getTransparencyMapping(vendor.getId(), acb.getId()); if (existingMap == null) { VendorACBMapDTO vendorMappingToUpdate = new VendorACBMapDTO(); vendorMappingToUpdate.setAcbId(acb.getId()); vendorMappingToUpdate.setVendorId(before.getId()); vendorMappingToUpdate.setTransparencyAttestation(vendor.getTransparencyAttestation()); vendorDao.createTransparencyMapping(vendorMappingToUpdate); } else { existingMap.setTransparencyAttestation(vendor.getTransparencyAttestation()); vendorDao.updateTransparencyMapping(existingMap); } } } } VendorDTO after = new VendorDTO(result); after.setTransparencyAttestation(vendor.getTransparencyAttestation()); activityManager.addActivity( ActivityConcept.ACTIVITY_CONCEPT_VENDOR, after.getId(), "Vendor " + vendor.getName() + " was updated.", before, after); return after; }
@Override public UcdProcessDTO update(UcdProcessDTO dto) throws EntityRetrievalException { UcdProcessEntity entity = this.getEntityById(dto.getId()); if (entity == null) { throw new EntityRetrievalException("Entity with id " + dto.getId() + " does not exist"); } entity.setName(dto.getName()); entity.setLastModifiedUser(Util.getCurrentUser().getId()); entity.setLastModifiedDate(new Date()); update(entity); return new UcdProcessDTO(entity); }
@Override public void update(CQMResultDTO cqmResult) throws EntityRetrievalException { CQMResultEntity entity = this.getEntityById(cqmResult.getId()); entity.setCqmCriterionId(cqmResult.getCqmCriterionId()); entity.setCreationDate(cqmResult.getCreationDate()); entity.setDeleted(cqmResult.getDeleted()); entity.setId(cqmResult.getId()); // entity.setLastModifiedDate(cqmResult.getLastModifiedDate()); entity.setLastModifiedUser(Util.getCurrentUser().getId()); ; entity.setSuccess(cqmResult.getSuccess()); update(entity); }
@Override public InvitationDTO create(InvitationDTO dto) throws UserCreationException { Date creationDate = new Date(); InvitationEntity toCreate = new InvitationEntity(); toCreate.setCreationDate(creationDate); toCreate.setDeleted(false); toCreate.setAcbId(dto.getAcbId()); toCreate.setEmailAddress(dto.getEmail()); toCreate.setToken(dto.getToken()); toCreate.setLastModifiedDate(new Date()); toCreate.setLastModifiedUser(Util.getCurrentUser().getId()); create(toCreate); return new InvitationDTO(toCreate); }