Exemple #1
0
  private int comparePublicationDate(WorkEntity other) {
    if (other.getPublicationDate() == null) {
      if (this.publicationDate == null) {
        return 0;
      } else {
        return 1;
      }
    } else if (this.publicationDate == null) {
      return -1;
    }

    return this.publicationDate.compareTo(other.getPublicationDate());
  }
Exemple #2
0
 private int compareTitles(WorkEntity other) {
   if (other.getTitle() == null) {
     if (title == null) {
       return 0;
     } else {
       return 1;
     }
   }
   if (title == null) {
     return -1;
   }
   return title.compareToIgnoreCase(other.getTitle());
 }
Exemple #3
0
 @Override
 @Transactional
 public WorkEntity editWork(WorkEntity updatedWork) {
   WorkEntity workToUpdate = this.find(updatedWork.getId());
   mergeWork(workToUpdate, updatedWork);
   workToUpdate = this.merge(workToUpdate);
   return workToUpdate;
 }
Exemple #4
0
    public int compare(WorkEntity work1, WorkEntity work2) {
      if (work2 == null) {
        throw new NullPointerException("Can't compare with null");
      }

      // Negate the result (Multiply it by -1) to reverse the order.
      int comparison = work1.comparePublicationDate(work2) * -1;

      if (comparison == 0) {
        comparison = work1.compareTitles(work2);
        if (comparison == 0) {
          return work1.compareIds(work2);
        }
      }

      return comparison;
    }
Exemple #5
0
 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());
 }
Exemple #6
0
 private void mergeWork(WorkEntity workToUpdate, WorkEntity workWithNewData) {
   workToUpdate.setTitle(workWithNewData.getTitle());
   workToUpdate.setTranslatedTitle(workWithNewData.getTranslatedTitle());
   workToUpdate.setSubtitle(workWithNewData.getSubtitle());
   workToUpdate.setDescription(workWithNewData.getDescription());
   workToUpdate.setWorkUrl(workWithNewData.getWorkUrl());
   workToUpdate.setCitation(workWithNewData.getCitation());
   workToUpdate.setJournalTitle(workWithNewData.getJournalTitle());
   workToUpdate.setLanguageCode(workWithNewData.getLanguageCode());
   workToUpdate.setTranslatedTitleLanguageCode(workWithNewData.getTranslatedTitleLanguageCode());
   workToUpdate.setIso2Country(workWithNewData.getIso2Country());
   workToUpdate.setCitationType(workWithNewData.getCitationType());
   workToUpdate.setWorkType(workWithNewData.getWorkType());
   workToUpdate.setPublicationDate(workWithNewData.getPublicationDate());
   workToUpdate.setContributorsJson(workWithNewData.getContributorsJson());
   workToUpdate.setExternalIdentifiersJson(workWithNewData.getExternalIdentifiersJson());
   workToUpdate.setVisibility(workWithNewData.getVisibility());
   workToUpdate.setDisplayIndex(workWithNewData.getDisplayIndex());
   workToUpdate.setSource(workWithNewData.getSource());
   workToUpdate.setLastModified(new Date());
   if (workWithNewData.getAddedToProfileDate() != null) {
     workToUpdate.setAddedToProfileDate(workWithNewData.getAddedToProfileDate());
   }
   workToUpdate.setProfile(workWithNewData.getProfile());
 }
Exemple #7
0
  @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());
  }