use of org.alien4cloud.alm.service.events.ServiceChangedEvent in project alien4cloud by alien4cloud.
the class ServiceResourceService method save.
/**
* Save the service resource and optionally checks that the name/version couple is unique.
* Check must be done for new resource or when the name or version has changed.
*
* @param serviceResource The service to save.
* @param ensureUniqueness True if we should process unicity check, false if not.
*/
public synchronized void save(ServiceResource serviceResource, boolean ensureUniqueness) {
if (ensureUniqueness) {
long count = alienDAO.buildQuery(ServiceResource.class).setFilters(fromKeyValueCouples("name", serviceResource.getName(), "version", serviceResource.getVersion())).count();
if (count > 0) {
throw new AlreadyExistException("A service with name <" + serviceResource.getName() + "> and version <" + serviceResource.getVersion() + "> already exists.");
}
}
// ensure that the nested version just reflects the version.
Version version = VersionUtil.parseVersion(serviceResource.getVersion());
serviceResource.setNestedVersion(version);
alienDAO.save(serviceResource);
publisher.publishEvent(new ServiceChangedEvent(this, serviceResource.getId()));
}
Aggregations