@Test(expected = AcmCreateObjectFailedException.class) public void testFailSaveOrganizationWithMissingPersonAssociationTypes() throws PipelineProcessException, AcmCreateObjectFailedException, AcmUpdateObjectFailedException { Organization organization = new Organization(); List<PersonOrganizationAssociation> personAssociations = new ArrayList<>(); PersonOrganizationAssociation personAssociation1 = new PersonOrganizationAssociation(); Person person1 = new Person(); person1.setId(1l); personAssociation1.setPerson(person1); personAssociation1.setOrganization(organization); personAssociation1.setOrganizationToPersonAssociationType("owned"); personAssociations.add(personAssociation1); PersonOrganizationAssociation personAssociation2 = new PersonOrganizationAssociation(); Person person2 = new Person(); person2.setId(2l); personAssociation2.setPerson(person2); personAssociation2.setOrganization(organization); personAssociation2.setPersonToOrganizationAssociationType("employee"); personAssociations.add(personAssociation2); organization.setPersonAssociations(personAssociations); organizationService.saveOrganization(organization, null, null); fail("AcmCreateObjectFailedException expected!"); }
@Override @Transactional public Organization saveOrganization(Organization organization, Authentication auth, String ipAddress) throws PipelineProcessException, AcmCreateObjectFailedException, AcmUpdateObjectFailedException { validatePersonAssociations(organization); try { ContactMethodsUtil.validateContactMethodFields(organization.getContactMethods()); } catch (AcmContactMethodValidationException e) { if (organization.getId() == null) { throw new AcmCreateObjectFailedException("Organization", e.toString(), null); } else { throw new AcmUpdateObjectFailedException("Organization", organization.getId(), e.toString(), null); } } OrganizationPipelineContext pipelineContext = new OrganizationPipelineContext(); pipelineContext.setNewOrganization(organization.getId() == null); pipelineContext.setAuthentication(auth); pipelineContext.setIpAddress(ipAddress); return organizationPipelineManager.executeOperation(organization, pipelineContext, () -> { Organization saved = organizationDao.save(organization); log.info("Organization saved '{}'", saved); return saved; }); }
OrganizationServiceImpl implements OrganizationService { @Override @Transactional public Organization saveOrganization(Organization organization, Authentication auth, String ipAddress) throws PipelineProcessException, AcmCreateObjectFailedException, AcmUpdateObjectFailedException { validatePersonAssociations(organization); try { ContactMethodsUtil.validateContactMethodFields(organization.getContactMethods()); } catch (AcmContactMethodValidationException e) { if (organization.getId() == null) { throw new AcmCreateObjectFailedException("Organization", e.toString(), null); } else { throw new AcmUpdateObjectFailedException("Organization", organization.getId(), e.toString(), null); } } OrganizationPipelineContext pipelineContext = new OrganizationPipelineContext(); pipelineContext.setNewOrganization(organization.getId() == null); pipelineContext.setAuthentication(auth); pipelineContext.setIpAddress(ipAddress); return organizationPipelineManager.executeOperation(organization, pipelineContext, () -> { Organization saved = organizationDao.save(organization); log.info("Organization saved '{}'", saved); return saved; }); } }
OrganizationServiceImpl implements OrganizationService { @Override @Transactional public Organization saveOrganization(Organization organization, Authentication auth, String ipAddress) throws PipelineProcessException, AcmCreateObjectFailedException, AcmUpdateObjectFailedException { validatePersonAssociations(organization); try { ContactMethodsUtil.validateContactMethodFields(organization.getContactMethods()); } catch (AcmContactMethodValidationException e) { if (organization.getId() == null) { throw new AcmCreateObjectFailedException("Organization", e.toString(), null); } else { throw new AcmUpdateObjectFailedException("Organization", organization.getId(), e.toString(), null); } } OrganizationPipelineContext pipelineContext = new OrganizationPipelineContext(); pipelineContext.setNewOrganization(organization.getId() == null); pipelineContext.setAuthentication(auth); pipelineContext.setIpAddress(ipAddress); return organizationPipelineManager.executeOperation(organization, pipelineContext, () -> { Organization saved = organizationDao.save(organization); log.info("Organization saved '{}'", saved); return saved; }); }  }
OrganizationServiceImpl implements OrganizationService { @Override @Transactional public Organization saveOrganization(Organization organization, Authentication auth, String ipAddress) throws PipelineProcessException, AcmCreateObjectFailedException, AcmUpdateObjectFailedException { validatePersonAssociations(organization); try { ContactMethodsUtil.validateContactMethodFields(organization.getContactMethods()); } catch (AcmContactMethodValidationException e) { if (organization.getId() == null) { throw new AcmCreateObjectFailedException("Organization", e.toString(), null); } else { throw new AcmUpdateObjectFailedException("Organization", organization.getId(), e.toString(), null); } } OrganizationPipelineContext pipelineContext = new OrganizationPipelineContext(); pipelineContext.setNewOrganization(organization.getId() == null); pipelineContext.setAuthentication(auth); pipelineContext.setIpAddress(ipAddress); return organizationPipelineManager.executeOperation(organization, pipelineContext, () -> { Organization saved = organizationDao.save(organization); log.info("Organization saved '{}'", saved); return saved; }); }  @Override Organization findOrCreateOrganization(String organizationName, String userId); @Override @Transactional Organization saveOrganization(Organization organization, Authentication auth, String ipAddress); @Override Organization getOrganization(Long organizationId); OrganizationDao getOrganizationDao(); void setOrganizationDao(OrganizationDao organizationDao); PipelineManager<Organization, OrganizationPipelineContext> getOrganizationPipelineManager(); void setOrganizationPipelineManager(PipelineManager<Organization, OrganizationPipelineContext> organizationPipelineManager); }
OrganizationServiceImpl implements OrganizationService { @Override @Transactional public Organization saveOrganization(Organization organization, Authentication auth, String ipAddress) throws PipelineProcessException, AcmCreateObjectFailedException, AcmUpdateObjectFailedException { validatePersonAssociations(organization); try { ContactMethodsUtil.validateContactMethodFields(organization.getContactMethods()); } catch (AcmContactMethodValidationException e) { if (organization.getId() == null) { throw new AcmCreateObjectFailedException("Organization", e.toString(), null); } else { throw new AcmUpdateObjectFailedException("Organization", organization.getId(), e.toString(), null); } } OrganizationPipelineContext pipelineContext = new OrganizationPipelineContext(); pipelineContext.setNewOrganization(organization.getId() == null); pipelineContext.setAuthentication(auth); pipelineContext.setIpAddress(ipAddress); return organizationPipelineManager.executeOperation(organization, pipelineContext, () -> { Organization saved = organizationDao.save(organization); log.info("Organization saved '{}'", saved); return saved; }); }  @Override Organization findOrCreateOrganization(String organizationName, String userId); @Override @Transactional Organization saveOrganization(Organization organization, Authentication auth, String ipAddress); @Override Organization getOrganization(Long organizationId); OrganizationDao getOrganizationDao(); void setOrganizationDao(OrganizationDao organizationDao); PipelineManager<Organization, OrganizationPipelineContext> getOrganizationPipelineManager(); void setOrganizationPipelineManager(PipelineManager<Organization, OrganizationPipelineContext> organizationPipelineManager);  }