/** * If for some reason the platform plugin is not available, this method can be called to add a "dummy" platform * resource. This is normally only used during tests. * @return A dummy platform for testing purposes only. */ private Resource getTestPlatform() { ResourceType type = this.pluginManager.getMetadataManager().addTestPlatformType(); if (this.platform != null && this.platform.getResourceType() == type) { return this.platform; } Set<Resource> childResources = new CopyOnWriteArraySet<Resource>( Collections.newSetFromMap(new ConcurrentHashMap<Resource, Boolean>())); Resource platform = new Resource(childResources); platform.setResourceKey("testkey" + configuration.getContainerName()); platform.setName("testplatform"); platform.setResourceType(type); platform.setUuid(UUID.randomUUID().toString()); platform.setAgent(this.agent); return platform; }
existingResource.setName(name); logMessage.append("name, ");
r.setName(request.getResourceName()); r = resMgr.updateResource(caller, r);
in.setName(resourceWithType.getResourceName()); in.setDescription(resourceWithType.getDescription()); in.setLocation(resourceWithType.getLocation());
static Resource createNewResource(DiscoveredResourceDetails details) { // 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.setUuid(UUID.randomUUID().toString()); resource.setResourceKey(details.getResourceKey()); resource.setName(details.getResourceName()); resource.setVersion(details.getResourceVersion()); resource.setDescription(details.getResourceDescription()); resource.setResourceType(details.getResourceType()); Configuration pluginConfiguration = details.getPluginConfiguration(); ConfigurationUtility.normalizeConfiguration(details.getPluginConfiguration(), details.getResourceType() .getPluginConfigurationDefinition(), false, false); resource.setPluginConfiguration(pluginConfiguration); return resource; }
String userSuppliedResourceName = matchingHistory.getCreatedResourceName(); if (!isBlank(userSuppliedResourceName) && !userSuppliedResourceName.equals(resource.getName())) { resource.setName(userSuppliedResourceName);
@Override public Resource updateResource(Subject user, Resource resource) { Resource persistedResource = entityManager.find(Resource.class, resource.getId()); if (persistedResource == null) { throw new ResourceNotFoundException(resource.getId()); } if (!authorizationManager.hasResourcePermission(user, Permission.MODIFY_RESOURCE, resource.getId())) { throw new PermissionException("You do not have permission to modify Resource with id " + resource.getId() + "."); } /*if (getResourceByParentAndKey(user, resource.getParentResource(), resource.getResourceKey()) != null) * { throw new ResourceAlreadyExistsException("Resource with key '" + resource.getName() + "' already * exists");}*/ // On name change make sure we update the ancestry as the name is part of the ancestry string if (!persistedResource.getName().equals(resource.getName())) { persistedResource.setName(resource.getName()); updateAncestry(persistedResource); } persistedResource.setLocation(resource.getLocation()); persistedResource.setDescription(resource.getDescription()); persistedResource.setAgentSynchronizationNeeded(); persistedResource.setModifiedBy(user.getName()); return entityManager.merge(persistedResource); }
resource.setName(name); logMessage.append("name, "); ret.setUpgradedResourceName(resource.getName());
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; }
public void updateResource(Resource resource) { if (getNewResourceKey() != null) { resource.setResourceKey(getNewResourceKey()); } if (getNewName() != null) { resource.setName(getNewName()); } if (getNewDescription() != null) { resource.setDescription(getNewDescription()); } if (getNewPluginConfiguration() != null) { resource.setPluginConfiguration(getNewPluginConfiguration()); } if (getNewVersion() != null) { resource.setVersion(getNewVersion()); } }
resource.setName(resource.getName().intern());
private static Resource convertToPojoResource(Resource resource, boolean includeDescendants) { Resource pojoResource = new Resource(resource.getId()); pojoResource.setUuid(resource.getUuid()); pojoResource.setResourceKey(resource.getResourceKey()); pojoResource.setResourceType(resource.getResourceType()); pojoResource.setMtime(resource.getMtime()); pojoResource.setInventoryStatus(resource.getInventoryStatus()); Configuration pcCopy = resource.getPluginConfiguration(); if (pcCopy != null) { pcCopy = pcCopy.deepCopy(); } pojoResource.setPluginConfiguration(pcCopy); pojoResource.setName(resource.getName()); pojoResource.setDescription(resource.getDescription()); pojoResource.setLocation(resource.getLocation()); pojoResource.setVersion(resource.getVersion()); if (resource.getParentResource() != null) { pojoResource.setParentResource(convertToPojoResource(resource.getParentResource(), false)); } if (includeDescendants) { for (Resource childResource : resource.getChildResources()) { if (isVisibleInInventory(childResource)) { pojoResource.addChildResource(convertToPojoResource(childResource, true)); } } } return pojoResource; }