@Test @Rollback(true) @Transactional(propagation = Propagation.REQUIRES_NEW) public void testAddWork() { String title = "New Work"; String subtitle = "Subtitle"; String citation = "Test citation"; String description = "Description for new work"; String url = "http://work.com"; WorkEntity work = new WorkEntity(); work.setCitation(citation); work.setCitationType(CitationType.FORMATTED_UNSPECIFIED); work.setDescription(description); work.setTitle(title); work.setSubtitle(subtitle); work.setWorkType(WorkType.BOOK); work.setWorkUrl(url); ProfileEntity profile = new ProfileEntity(USER_ORCID); work.setProfile(profile); work.setSourceId(USER_ORCID); work.setAddedToProfileDate(new Date()); assertNull(work.getId()); try { work = workDao.addWork(work); } catch (Exception e) { fail(); } assertNotNull(work.getId()); }
@Override @Transactional public WorkEntity editWork(WorkEntity updatedWork) { WorkEntity workToUpdate = this.find(updatedWork.getId()); mergeWork(workToUpdate, updatedWork); workToUpdate = this.merge(workToUpdate); return workToUpdate; }
private int compareIds(WorkEntity other) { if (other.getId() == null) { if (id == null) { if (equals(other)) { return 0; } else { // If can't determine preferred order, then be polite and // say 'after you!' return -1; } } else { return 1; } } if (id == null) { return -1; } return id.compareTo(other.getId()); }