/** * Starts a new availability interval for a given resource. If the new interval is of the same type as the previous, * then the previous will be extended. Otherwise the previous will be terminated and a new one will be started. The * Availability objects in the given record will be modified; make sure they are managed by an entity manager if you * want the changes to be persisted. * * @param record identifies the resource and its current availability * @param startDate Start date of the new interval (which must be after the current availability interval) * @param aType the new type of availability (UP, DOWN) that the resource will now have * * @return the new availability interval for a given resource, or null if there is already an existing availability */ private Availability getNewInterval(ResourceIdWithAvailabilityComposite record, Date startDate, AvailabilityType aType) { // if there is already an existing availability, update it Availability old = record.getAvailability(); if (old != null) { if (old.getAvailabilityType() == aType) { // existing availability is the same type, just extend it without creating a new entity old.setEndTime(null); // don't really need to do this; just enforces the fact that we extend the last interval return null; } old.setEndTime(startDate.getTime()); } Resource resource = new Resource(); resource.setId(record.getResourceId()); Availability newAvail = new Availability(resource, startDate.getTime(), aType); entityManager.persist(newAvail); return newAvail; }
resource.setId(this.temporaryKeyIndex.decrementAndGet()); resource.setInventoryStatus(InventoryStatus.COMMITTED);
resource.setId(mergeResourceResponse.getResourceId()); resource.setMtime(mergeResourceResponse.getMtime()); Set newResources = new LinkedHashSet<Resource>();
bareResource.setId(res.getId()); bareResource.setUuid(res.getUuid());
resource.setId(syncInfo.getId()); resource.setMtime(syncInfo.getMtime()); resource.setInventoryStatus(syncInfo.getInventoryStatus());
private Resource cloneResourceWithoutChildren(Resource resourceFromServer) { // Use a CopyOnWriteArraySet for childResources to allow the field to be concurrently accessed safely // (i.e. to avoid ConcurrentModificationExceptions). Set<Resource> childResources = new CopyOnWriteArraySet<Resource>(); Resource resource = new Resource(childResources); resource.setId(resourceFromServer.getId()); resource.setUuid(resourceFromServer.getUuid()); resource.setResourceKey(resourceFromServer.getResourceKey()); resource.setResourceType(resourceFromServer.getResourceType()); resource.setMtime(resourceFromServer.getMtime()); resource.setInventoryStatus(resourceFromServer.getInventoryStatus()); resource.setPluginConfiguration(resourceFromServer.getPluginConfiguration()); resource.setVersion(resourceFromServer.getVersion()); resource.setName(resourceFromServer.getName()); compactResource(resource); return resource; }
private boolean mergeResource(Resource sourceResource, Resource targetResource) { if (targetResource.getId() != 0 && targetResource.getId() != sourceResource.getId()) { log.warn("Id for " + targetResource + " changed from [" + targetResource.getId() + "] to [" + sourceResource.getId() + "]."); } targetResource.setId(sourceResource.getId()); targetResource.setUuid(sourceResource.getUuid()); if (!targetResource.getResourceKey().equals(sourceResource.getResourceKey())) { log.warn("Resource key for " + targetResource + " changed from [" + targetResource.getResourceKey() + "] to [" + sourceResource.getResourceKey() + "]."); } targetResource.setResourceKey(sourceResource.getResourceKey()); targetResource.setResourceType(sourceResource.getResourceType()); targetResource.setMtime(sourceResource.getMtime()); targetResource.setInventoryStatus(sourceResource.getInventoryStatus()); // (jshaughn) noticed we don't set the version here, should we? boolean pluginConfigUpdated = (!targetResource.getPluginConfiguration().equals( sourceResource.getPluginConfiguration())); targetResource.setPluginConfiguration(sourceResource.getPluginConfiguration()); targetResource.setName(sourceResource.getName()); compactResource(targetResource); return pluginConfigUpdated; }