@Test public final void testSaveRunningTargetInstance() { TargetInstance aTargetInstance = tiDao.load(5001L); aTargetInstance.setActualStartTime(new Date()); aTargetInstance.setState(TargetInstance.STATE_RUNNING); aTargetInstance.setHarvestServer("My Local Agent"); Profile orig_p = aTargetInstance.getProfile(); testInstance.save(aTargetInstance); Profile new_p = aTargetInstance.getProfile(); assertTrue(orig_p.getOid() != new_p.getOid()); assertTrue(orig_p.getOid() == new_p.getOrigOid()); assertFalse(orig_p.isLocked()); assertTrue(new_p.isLocked()); assertTrue(orig_p.getProfile().length() > 0); assertEquals(orig_p.getProfile(), new_p.getProfile()); }
public void save(TargetInstance aTargetInstance) { TargetInstanceDTO origTi = targetInstanceDao.getTargetInstanceDTO(aTargetInstance.getOid()); if (TargetInstance.STATE_RUNNING.equals(aTargetInstance.getState())) { Profile currentProfile = aTargetInstance.getProfile(); if(!currentProfile.isLocked()) { Profile newProfile = currentProfile.clone(); newProfile.setOrigOid(currentProfile.getOid()); newProfile.setName(newProfile.getName()+" Locked(v"+newProfile.getVersion()+")"); ProfileDTO dto = profileDAO.getLockedDTO(newProfile.getOrigOid(), newProfile.getVersion()); if(dto == null) { profileDAO.saveOrUpdate(newProfile); dto = profileDAO.getLockedDTO(newProfile.getOrigOid(), newProfile.getVersion()); } aTargetInstance.setLockedProfile(profileDAO.load(dto.getOid())); if(aTargetInstance.getOverrides() == null && aTargetInstance.getTarget() != null && aTargetInstance.getTarget().getOverrides() != null) { ProfileOverrides overrides = aTargetInstance.getTarget().getOverrides().copy(); aTargetInstance.setOverrides(overrides); } } } targetInstanceDao.save(aTargetInstance); if (aTargetInstance.getAnnotations() != null && !aTargetInstance.getAnnotations().isEmpty()) { annotationDAO.saveAnnotations(aTargetInstance.getAnnotations()); } if (aTargetInstance.getDeletedAnnotations() != null && !aTargetInstance.getDeletedAnnotations().isEmpty()) { annotationDAO.deleteAnnotations(aTargetInstance.getDeletedAnnotations()); } if (TargetInstance.STATE_ENDORSED.equals(aTargetInstance.getState()) || TargetInstance.STATE_REJECTED.equals(aTargetInstance.getState()) || TargetInstance.STATE_ARCHIVED.equals(aTargetInstance.getState())) { inTrayManager.deleteTasks(aTargetInstance.getOid(), aTargetInstance.getResourceType(), MessageType.TARGET_INSTANCE_ENDORSE); } if (TargetInstance.STATE_HARVESTED.equals(origTi.getState()) && TargetInstance.STATE_ENDORSED.equals(aTargetInstance.getState())) { inTrayManager.generateTask(Privilege.ARCHIVE_HARVEST, MessageType.TARGET_INSTANCE_ARCHIVE, aTargetInstance); } if (TargetInstance.STATE_ARCHIVED.equals(aTargetInstance.getState())) { inTrayManager.deleteTasks(aTargetInstance.getOid(), aTargetInstance.getResourceType(), MessageType.TARGET_INSTANCE_ARCHIVE); } }
TargetInstanceManagerImpl implements TargetInstanceManager { public void save(TargetInstance aTargetInstance) { TargetInstanceDTO origTi = targetInstanceDao.getTargetInstanceDTO(aTargetInstance.getOid()); if (TargetInstance.STATE_RUNNING.equals(aTargetInstance.getState())) { Profile currentProfile = aTargetInstance.getProfile(); if(!currentProfile.isLocked()) { Profile newProfile = currentProfile.clone(); newProfile.setOrigOid(currentProfile.getOid()); newProfile.setName(newProfile.getName()+" Locked(v"+newProfile.getVersion()+")"); ProfileDTO dto = profileDAO.getLockedDTO(newProfile.getOrigOid(), newProfile.getVersion()); if(dto == null) { profileDAO.saveOrUpdate(newProfile); dto = profileDAO.getLockedDTO(newProfile.getOrigOid(), newProfile.getVersion()); } aTargetInstance.setLockedProfile(profileDAO.load(dto.getOid())); if(aTargetInstance.getOverrides() == null && aTargetInstance.getTarget() != null && aTargetInstance.getTarget().getOverrides() != null) { ProfileOverrides overrides = aTargetInstance.getTarget().getOverrides().copy(); aTargetInstance.setOverrides(overrides); } } } targetInstanceDao.save(aTargetInstance); if (aTargetInstance.getAnnotations() != null && !aTargetInstance.getAnnotations().isEmpty()) { annotationDAO.saveAnnotations(aTargetInstance.getAnnotations()); } if (aTargetInstance.getDeletedAnnotations() != null && !aTargetInstance.getDeletedAnnotations().isEmpty()) { annotationDAO.deleteAnnotations(aTargetInstance.getDeletedAnnotations()); } if (TargetInstance.STATE_ENDORSED.equals(aTargetInstance.getState()) || TargetInstance.STATE_REJECTED.equals(aTargetInstance.getState()) || TargetInstance.STATE_ARCHIVED.equals(aTargetInstance.getState())) { inTrayManager.deleteTasks(aTargetInstance.getOid(), aTargetInstance.getResourceType(), MessageType.TARGET_INSTANCE_ENDORSE); } if (TargetInstance.STATE_HARVESTED.equals(origTi.getState()) && TargetInstance.STATE_ENDORSED.equals(aTargetInstance.getState())) { inTrayManager.generateTask(Privilege.ARCHIVE_HARVEST, MessageType.TARGET_INSTANCE_ARCHIVE, aTargetInstance); } if (TargetInstance.STATE_ARCHIVED.equals(aTargetInstance.getState())) { inTrayManager.deleteTasks(aTargetInstance.getOid(), aTargetInstance.getResourceType(), MessageType.TARGET_INSTANCE_ARCHIVE); } } }
TargetInstanceManagerImpl implements TargetInstanceManager { public void save(TargetInstance aTargetInstance) { TargetInstanceDTO origTi = targetInstanceDao.getTargetInstanceDTO(aTargetInstance.getOid()); if (TargetInstance.STATE_RUNNING.equals(aTargetInstance.getState())) { Profile currentProfile = aTargetInstance.getProfile(); if(!currentProfile.isLocked()) { Profile newProfile = currentProfile.clone(); newProfile.setOrigOid(currentProfile.getOid()); newProfile.setName(newProfile.getName()+" Locked(v"+newProfile.getVersion()+")"); ProfileDTO dto = profileDAO.getLockedDTO(newProfile.getOrigOid(), newProfile.getVersion()); if(dto == null) { profileDAO.saveOrUpdate(newProfile); dto = profileDAO.getLockedDTO(newProfile.getOrigOid(), newProfile.getVersion()); } aTargetInstance.setLockedProfile(profileDAO.load(dto.getOid())); if(aTargetInstance.getOverrides() == null && aTargetInstance.getTarget() != null && aTargetInstance.getTarget().getOverrides() != null) { ProfileOverrides overrides = aTargetInstance.getTarget().getOverrides().copy(); aTargetInstance.setOverrides(overrides); } } } targetInstanceDao.save(aTargetInstance); if (aTargetInstance.getAnnotations() != null && !aTargetInstance.getAnnotations().isEmpty()) { annotationDAO.saveAnnotations(aTargetInstance.getAnnotations()); } if (aTargetInstance.getDeletedAnnotations() != null && !aTargetInstance.getDeletedAnnotations().isEmpty()) { annotationDAO.deleteAnnotations(aTargetInstance.getDeletedAnnotations()); } if (TargetInstance.STATE_ENDORSED.equals(aTargetInstance.getState()) || TargetInstance.STATE_REJECTED.equals(aTargetInstance.getState()) || TargetInstance.STATE_ARCHIVED.equals(aTargetInstance.getState())) { inTrayManager.deleteTasks(aTargetInstance.getOid(), aTargetInstance.getResourceType(), MessageType.TARGET_INSTANCE_ENDORSE); } if (TargetInstance.STATE_HARVESTED.equals(origTi.getState()) && TargetInstance.STATE_ENDORSED.equals(aTargetInstance.getState())) { inTrayManager.generateTask(Privilege.ARCHIVE_HARVEST, MessageType.TARGET_INSTANCE_ARCHIVE, aTargetInstance); } if (TargetInstance.STATE_ARCHIVED.equals(aTargetInstance.getState())) { inTrayManager.deleteTasks(aTargetInstance.getOid(), aTargetInstance.getResourceType(), MessageType.TARGET_INSTANCE_ARCHIVE); } }  }
TargetInstanceManagerImpl implements TargetInstanceManager { public void save(TargetInstance aTargetInstance) { TargetInstanceDTO origTi = targetInstanceDao.getTargetInstanceDTO(aTargetInstance.getOid()); if (TargetInstance.STATE_RUNNING.equals(aTargetInstance.getState())) { Profile currentProfile = aTargetInstance.getProfile(); if(!currentProfile.isLocked()) { Profile newProfile = currentProfile.clone(); newProfile.setOrigOid(currentProfile.getOid()); newProfile.setName(newProfile.getName()+" Locked(v"+newProfile.getVersion()+")"); ProfileDTO dto = profileDAO.getLockedDTO(newProfile.getOrigOid(), newProfile.getVersion()); if(dto == null) { profileDAO.saveOrUpdate(newProfile); dto = profileDAO.getLockedDTO(newProfile.getOrigOid(), newProfile.getVersion()); } aTargetInstance.setLockedProfile(profileDAO.load(dto.getOid())); if(aTargetInstance.getOverrides() == null && aTargetInstance.getTarget() != null && aTargetInstance.getTarget().getOverrides() != null) { ProfileOverrides overrides = aTargetInstance.getTarget().getOverrides().copy(); aTargetInstance.setOverrides(overrides); } } } targetInstanceDao.save(aTargetInstance); if (aTargetInstance.getAnnotations() != null && !aTargetInstance.getAnnotations().isEmpty()) { annotationDAO.saveAnnotations(aTargetInstance.getAnnotations()); } if (aTargetInstance.getDeletedAnnotations() != null && !aTargetInstance.getDeletedAnnotations().isEmpty()) { annotationDAO.deleteAnnotations(aTargetInstance.getDeletedAnnotations()); } if (TargetInstance.STATE_ENDORSED.equals(aTargetInstance.getState()) || TargetInstance.STATE_REJECTED.equals(aTargetInstance.getState()) || TargetInstance.STATE_ARCHIVED.equals(aTargetInstance.getState())) { inTrayManager.deleteTasks(aTargetInstance.getOid(), aTargetInstance.getResourceType(), MessageType.TARGET_INSTANCE_ENDORSE); } if (TargetInstance.STATE_HARVESTED.equals(origTi.getState()) && TargetInstance.STATE_ENDORSED.equals(aTargetInstance.getState())) { inTrayManager.generateTask(Privilege.ARCHIVE_HARVEST, MessageType.TARGET_INSTANCE_ARCHIVE, aTargetInstance); } if (TargetInstance.STATE_ARCHIVED.equals(aTargetInstance.getState())) { inTrayManager.deleteTasks(aTargetInstance.getOid(), aTargetInstance.getResourceType(), MessageType.TARGET_INSTANCE_ARCHIVE); } }  void setStoreSeedHistory(boolean storeSeedHistory); boolean getStoreSeedHistory(); Pagination search(final TargetInstanceCriteria aCriteria); Pagination search(final TargetInstanceCriteria aCriteria, final int aPage, final int aPageSize); TargetInstance getNextTargetInstanceToHarvest(); List<QueuedTargetInstanceDTO> getQueue(); List<QueuedTargetInstanceDTO> getQueueForTarget(Long targetOid); Long countQueueLengthForTarget(final Long targetOid); TargetInstance getTargetInstance(Long aOid); TargetInstance getTargetInstance(Long aOid, boolean aLoadFully); void delete(TargetInstance aTargetInstance); void save(TargetInstance aTargetInstance); void save(HarvestResult aHarvestResult); void saveOrUpdate(Indicator indicator); void saveOrUpdate(IndicatorReportLine indicatorReportLine); List<Annotation> getAnnotations(TargetInstance aTargetInstance); int countTargetInstances(User aUser, ArrayList<String> aStates); int countTargetInstancesByTarget(Long Oid); void setTargetInstanceDao(TargetInstanceDAO targetInstanceDao); void setAuditor(Auditor auditor); void setAnnotationDAO(AnnotationDAO annotationDAO); void setProfileDAO(ProfileDAO profileDAO); void setInTrayManager(InTrayManager inTrayManager); void saveAll(Collection<TargetInstance> aCollection); void deleteTargetInstances(Long aTargetOid, Long aScheduleOid); List<HarvestHistoryDTO> getHarvestHistory(Long targetOid); List<HarvestResult> getHarvestResults(Long targetInstanceOid); HarvestResourceDTO getHarvestResourceDTO(final long harvestResultOid, final String resource); void purgeTargetInstance(TargetInstance aTargetInstance); void setIndicatorDAO(IndicatorDAO indicatorDAO); IndicatorDAO getIndicatorDAO(); IndicatorCriteriaDAO getIndicatorCriteriaDAO(); List<IndicatorCriteria> getIndicatorCriterias(); List<IndicatorCriteria> getIndicatorCriteriasByAgencyOid(Long agencyOid); void setIndicatorCriteriaDAO(IndicatorCriteriaDAO indicatorCriteriaDAO); void setIndicatorReportLineDAO(IndicatorReportLineDAO indicatorReportLineDAO); void deleteIndicatorReportLines(Indicator indicator); }
TargetInstanceManagerImpl implements TargetInstanceManager { public void save(TargetInstance aTargetInstance) { TargetInstanceDTO origTi = targetInstanceDao.getTargetInstanceDTO(aTargetInstance.getOid()); if (TargetInstance.STATE_RUNNING.equals(aTargetInstance.getState())) { Profile currentProfile = aTargetInstance.getProfile(); if(!currentProfile.isLocked()) { Profile newProfile = currentProfile.clone(); newProfile.setOrigOid(currentProfile.getOid()); newProfile.setName(newProfile.getName()+" Locked(v"+newProfile.getVersion()+")"); ProfileDTO dto = profileDAO.getLockedDTO(newProfile.getOrigOid(), newProfile.getVersion()); if(dto == null) { profileDAO.saveOrUpdate(newProfile); dto = profileDAO.getLockedDTO(newProfile.getOrigOid(), newProfile.getVersion()); } aTargetInstance.setLockedProfile(profileDAO.load(dto.getOid())); if(aTargetInstance.getOverrides() == null && aTargetInstance.getTarget() != null && aTargetInstance.getTarget().getOverrides() != null) { ProfileOverrides overrides = aTargetInstance.getTarget().getOverrides().copy(); aTargetInstance.setOverrides(overrides); } } } targetInstanceDao.save(aTargetInstance); if (aTargetInstance.getAnnotations() != null && !aTargetInstance.getAnnotations().isEmpty()) { annotationDAO.saveAnnotations(aTargetInstance.getAnnotations()); } if (aTargetInstance.getDeletedAnnotations() != null && !aTargetInstance.getDeletedAnnotations().isEmpty()) { annotationDAO.deleteAnnotations(aTargetInstance.getDeletedAnnotations()); } if (TargetInstance.STATE_ENDORSED.equals(aTargetInstance.getState()) || TargetInstance.STATE_REJECTED.equals(aTargetInstance.getState()) || TargetInstance.STATE_ARCHIVED.equals(aTargetInstance.getState())) { inTrayManager.deleteTasks(aTargetInstance.getOid(), aTargetInstance.getResourceType(), MessageType.TARGET_INSTANCE_ENDORSE); } if (TargetInstance.STATE_HARVESTED.equals(origTi.getState()) && TargetInstance.STATE_ENDORSED.equals(aTargetInstance.getState())) { inTrayManager.generateTask(Privilege.ARCHIVE_HARVEST, MessageType.TARGET_INSTANCE_ARCHIVE, aTargetInstance); } if (TargetInstance.STATE_ARCHIVED.equals(aTargetInstance.getState())) { inTrayManager.deleteTasks(aTargetInstance.getOid(), aTargetInstance.getResourceType(), MessageType.TARGET_INSTANCE_ARCHIVE); } }  void setStoreSeedHistory(boolean storeSeedHistory); boolean getStoreSeedHistory(); Pagination search(final TargetInstanceCriteria aCriteria); Pagination search(final TargetInstanceCriteria aCriteria, final int aPage, final int aPageSize); TargetInstance getNextTargetInstanceToHarvest(); List<QueuedTargetInstanceDTO> getQueue(); List<QueuedTargetInstanceDTO> getQueueForTarget(Long targetOid); Long countQueueLengthForTarget(final Long targetOid); TargetInstance getTargetInstance(Long aOid); TargetInstance getTargetInstance(Long aOid, boolean aLoadFully); void delete(TargetInstance aTargetInstance); void save(TargetInstance aTargetInstance); void save(HarvestResult aHarvestResult); void saveOrUpdate(Indicator indicator); void saveOrUpdate(IndicatorReportLine indicatorReportLine); List<Annotation> getAnnotations(TargetInstance aTargetInstance); int countTargetInstances(User aUser, ArrayList<String> aStates); int countTargetInstancesByTarget(Long Oid); void setTargetInstanceDao(TargetInstanceDAO targetInstanceDao); void setAuditor(Auditor auditor); void setAnnotationDAO(AnnotationDAO annotationDAO); void setProfileDAO(ProfileDAO profileDAO); void setInTrayManager(InTrayManager inTrayManager); void saveAll(Collection<TargetInstance> aCollection); void deleteTargetInstances(Long aTargetOid, Long aScheduleOid); List<HarvestHistoryDTO> getHarvestHistory(Long targetOid); List<HarvestResult> getHarvestResults(Long targetInstanceOid); HarvestResourceDTO getHarvestResourceDTO(final long harvestResultOid, final String resource); void purgeTargetInstance(TargetInstance aTargetInstance); void setIndicatorDAO(IndicatorDAO indicatorDAO); IndicatorDAO getIndicatorDAO(); IndicatorCriteriaDAO getIndicatorCriteriaDAO(); List<IndicatorCriteria> getIndicatorCriterias(); List<IndicatorCriteria> getIndicatorCriteriasByAgencyOid(Long agencyOid); void setIndicatorCriteriaDAO(IndicatorCriteriaDAO indicatorCriteriaDAO); void setIndicatorReportLineDAO(IndicatorReportLineDAO indicatorReportLineDAO); void deleteIndicatorReportLines(Indicator indicator);  }