@Test(expected = AcmCreateObjectFailedException.class) public void testFailSavePersonWithMissingOrganizationAssociationTypes() throws AcmObjectNotFoundException, AcmCreateObjectFailedException, AcmUpdateObjectFailedException, AcmUserActionFailedException, PipelineProcessException { Person person = new Person(); List<PersonOrganizationAssociation> organizationAssociations = new ArrayList<>(); PersonOrganizationAssociation organizationAssociation1 = new PersonOrganizationAssociation(); Organization organization1 = new Organization(); organization1.setOrganizationId(1l); organizationAssociation1.setOrganization(organization1); organizationAssociation1.setPerson(person); organizationAssociation1.setOrganizationToPersonAssociationType("owned"); organizationAssociations.add(organizationAssociation1); PersonOrganizationAssociation organizationAssociation2 = new PersonOrganizationAssociation(); Organization organization2 = new Organization(); organization2.setOrganizationId(2l); organizationAssociation2.setOrganization(organization2); organizationAssociation2.setPerson(person); organizationAssociation2.setPersonToOrganizationAssociationType("employee"); organizationAssociations.add(organizationAssociation2); person.setOrganizationAssociations(organizationAssociations); personService.savePerson(person, null); fail("AcmCreateObjectFailedException expected!"); }
@Override public Person savePerson(Person in, Authentication authentication) throws AcmCreateObjectFailedException, AcmUpdateObjectFailedException, PipelineProcessException { validateOrganizationAssociations(in); try { ContactMethodsUtil.validateContactMethodFields(in.getContactMethods()); } catch (AcmContactMethodValidationException e) { if (in.getId() == null) { throw new AcmCreateObjectFailedException("Person", e.toString(), null); } else { throw new AcmUpdateObjectFailedException("Person", in.getId(), e.toString(), null); } } PersonPipelineContext pipelineContext = new PersonPipelineContext(); pipelineContext.setNewPerson(in.getId() == null); pipelineContext.setAuthentication(authentication); return personPipelineManager.executeOperation(in, pipelineContext, () -> { boolean isNew = in.getId() == null; Person oldPerson = null; if (!isNew) { String old = getObjectConverter().getJsonMarshaller().marshal(personDao.find(in.getId())); oldPerson = getObjectConverter().getJsonUnmarshaller().unmarshall(old, Person.class); } Person person = personDao.save(in); personEventPublisher.publishPersonUpsertEvents(person, oldPerson, isNew, true); return person; }); }
PersonServiceImpl implements PersonService { @Override public Person savePerson(Person in, Authentication authentication) throws AcmCreateObjectFailedException, AcmUpdateObjectFailedException, PipelineProcessException { validateOrganizationAssociations(in); try { ContactMethodsUtil.validateContactMethodFields(in.getContactMethods()); } catch (AcmContactMethodValidationException e) { if (in.getId() == null) { throw new AcmCreateObjectFailedException("Person", e.toString(), null); } else { throw new AcmUpdateObjectFailedException("Person", in.getId(), e.toString(), null); } } PersonPipelineContext pipelineContext = new PersonPipelineContext(); pipelineContext.setNewPerson(in.getId() == null); pipelineContext.setAuthentication(authentication); return personPipelineManager.executeOperation(in, pipelineContext, () -> { boolean isNew = in.getId() == null; Person oldPerson = null; if (!isNew) { String old = getObjectConverter().getJsonMarshaller().marshal(personDao.find(in.getId())); oldPerson = getObjectConverter().getJsonUnmarshaller().unmarshall(old, Person.class); } Person person = personDao.save(in); personEventPublisher.publishPersonUpsertEvents(person, oldPerson, isNew, true); return person; }); } }
PersonServiceImpl implements PersonService { @Override public Person savePerson(Person in, Authentication authentication) throws AcmCreateObjectFailedException, AcmUpdateObjectFailedException, PipelineProcessException { validateOrganizationAssociations(in); try { ContactMethodsUtil.validateContactMethodFields(in.getContactMethods()); } catch (AcmContactMethodValidationException e) { if (in.getId() == null) { throw new AcmCreateObjectFailedException("Person", e.toString(), null); } else { throw new AcmUpdateObjectFailedException("Person", in.getId(), e.toString(), null); } } PersonPipelineContext pipelineContext = new PersonPipelineContext(); pipelineContext.setNewPerson(in.getId() == null); pipelineContext.setAuthentication(authentication); return personPipelineManager.executeOperation(in, pipelineContext, () -> { boolean isNew = in.getId() == null; Person oldPerson = null; if (!isNew) { String old = getObjectConverter().getJsonMarshaller().marshal(personDao.find(in.getId())); oldPerson = getObjectConverter().getJsonUnmarshaller().unmarshall(old, Person.class); } Person person = personDao.save(in); personEventPublisher.publishPersonUpsertEvents(person, oldPerson, isNew, true); return person; }); }  }
PersonServiceImpl implements PersonService { @Override public Person savePerson(Person in, Authentication authentication) throws AcmCreateObjectFailedException, AcmUpdateObjectFailedException, PipelineProcessException { validateOrganizationAssociations(in); try { ContactMethodsUtil.validateContactMethodFields(in.getContactMethods()); } catch (AcmContactMethodValidationException e) { if (in.getId() == null) { throw new AcmCreateObjectFailedException("Person", e.toString(), null); } else { throw new AcmUpdateObjectFailedException("Person", in.getId(), e.toString(), null); } } PersonPipelineContext pipelineContext = new PersonPipelineContext(); pipelineContext.setNewPerson(in.getId() == null); pipelineContext.setAuthentication(authentication); return personPipelineManager.executeOperation(in, pipelineContext, () -> { boolean isNew = in.getId() == null; Person oldPerson = null; if (!isNew) { String old = getObjectConverter().getJsonMarshaller().marshal(personDao.find(in.getId())); oldPerson = getObjectConverter().getJsonUnmarshaller().unmarshall(old, Person.class); } Person person = personDao.save(in); personEventPublisher.publishPersonUpsertEvents(person, oldPerson, isNew, true); return person; }); }  @Override Person get(Long id); @Override Person addPersonIdentification(String key, String value, Person person); @Override Person addPersonIdentifications(List<String> keys, Person person); @Override Person setPersonIdentifications(List<Identification> identifications, Person person); @Override String getPersonType(FrevvoPerson person); @Override List<String> getPersonIdentificationKeys(FrevvoPerson person); @Override void deleteImageForPerson(Long personId, Long imageId); @Override EcmFile insertImageForPerson(Person person, MultipartFile image, boolean isDefault, String description, Authentication auth); @Override @Transactional EcmFile saveImageForPerson(Long personId, MultipartFile image, boolean isDefault, EcmFile metadata, Authentication auth); @Override Person savePerson(Person in, Authentication authentication); @Override Person savePerson(Person person, List<MultipartFile> pictures, Authentication authentication); PersonDao getPersonDao(); void setPersonDao(PersonDao personDao); void setEcmFileService(EcmFileService ecmFileService); void setAcmFolderService(AcmFolderService acmFolderService); void setFolderAndFilesUtils(FolderAndFilesUtils folderAndFilesUtils); PersonEventPublisher getPersonEventPublisher(); void setPersonEventPublisher(PersonEventPublisher personEventPublisher); PipelineManager<Person, PersonPipelineContext> getPersonPipelineManager(); void setPersonPipelineManager(PipelineManager<Person, PersonPipelineContext> personPipelineManager); EcmFileParticipantService getFileParticipantService(); void setFileParticipantService(EcmFileParticipantService fileParticipantService); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter); void setEcmTikaFileService(EcmTikaFileService ecmTikaFileService); PersonConfig getPersonConfig(); void setPersonConfig(PersonConfig personConfig); }
PersonServiceImpl implements PersonService { @Override public Person savePerson(Person in, Authentication authentication) throws AcmCreateObjectFailedException, AcmUpdateObjectFailedException, PipelineProcessException { validateOrganizationAssociations(in); try { ContactMethodsUtil.validateContactMethodFields(in.getContactMethods()); } catch (AcmContactMethodValidationException e) { if (in.getId() == null) { throw new AcmCreateObjectFailedException("Person", e.toString(), null); } else { throw new AcmUpdateObjectFailedException("Person", in.getId(), e.toString(), null); } } PersonPipelineContext pipelineContext = new PersonPipelineContext(); pipelineContext.setNewPerson(in.getId() == null); pipelineContext.setAuthentication(authentication); return personPipelineManager.executeOperation(in, pipelineContext, () -> { boolean isNew = in.getId() == null; Person oldPerson = null; if (!isNew) { String old = getObjectConverter().getJsonMarshaller().marshal(personDao.find(in.getId())); oldPerson = getObjectConverter().getJsonUnmarshaller().unmarshall(old, Person.class); } Person person = personDao.save(in); personEventPublisher.publishPersonUpsertEvents(person, oldPerson, isNew, true); return person; }); }  @Override Person get(Long id); @Override Person addPersonIdentification(String key, String value, Person person); @Override Person addPersonIdentifications(List<String> keys, Person person); @Override Person setPersonIdentifications(List<Identification> identifications, Person person); @Override String getPersonType(FrevvoPerson person); @Override List<String> getPersonIdentificationKeys(FrevvoPerson person); @Override void deleteImageForPerson(Long personId, Long imageId); @Override EcmFile insertImageForPerson(Person person, MultipartFile image, boolean isDefault, String description, Authentication auth); @Override @Transactional EcmFile saveImageForPerson(Long personId, MultipartFile image, boolean isDefault, EcmFile metadata, Authentication auth); @Override Person savePerson(Person in, Authentication authentication); @Override Person savePerson(Person person, List<MultipartFile> pictures, Authentication authentication); PersonDao getPersonDao(); void setPersonDao(PersonDao personDao); void setEcmFileService(EcmFileService ecmFileService); void setAcmFolderService(AcmFolderService acmFolderService); void setFolderAndFilesUtils(FolderAndFilesUtils folderAndFilesUtils); PersonEventPublisher getPersonEventPublisher(); void setPersonEventPublisher(PersonEventPublisher personEventPublisher); PipelineManager<Person, PersonPipelineContext> getPersonPipelineManager(); void setPersonPipelineManager(PipelineManager<Person, PersonPipelineContext> personPipelineManager); EcmFileParticipantService getFileParticipantService(); void setFileParticipantService(EcmFileParticipantService fileParticipantService); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter); void setEcmTikaFileService(EcmTikaFileService ecmTikaFileService); PersonConfig getPersonConfig(); void setPersonConfig(PersonConfig personConfig);  }