use of eu.openminted.registry.core.domain.Resource in project resource-catalogue by madgeek-arc.
the class PendingServiceManager method transformToActive.
@Override
@CacheEvict(cacheNames = { CACHE_VISITS, CACHE_PROVIDERS, CACHE_FEATURED }, allEntries = true)
public InfraService transformToActive(InfraService infraService, Authentication auth) {
logger.trace("User '{}' is attempting to transform the Pending Service with id {} to Active", auth, infraService.getId());
infraServiceService.validate(infraService);
infraServiceService.validateCategories(infraService.getService().getCategories());
infraServiceService.validateScientificDomains(infraService.getService().getScientificDomains());
// update loggingInfo
LoggingInfo loggingInfo = LoggingInfo.createLoggingInfoEntry(User.of(auth).getEmail(), User.of(auth).getFullName(), securityService.getRoleName(auth), LoggingInfo.Types.ONBOARD.getKey(), LoggingInfo.ActionType.REGISTERED.getKey());
List<LoggingInfo> loggingInfoList = new ArrayList<>();
if (infraService.getLoggingInfo() != null) {
loggingInfoList = infraService.getLoggingInfo();
loggingInfoList.add(loggingInfo);
} else {
loggingInfoList.add(loggingInfo);
}
infraService.setLoggingInfo(loggingInfoList);
// latestOnboardInfo
infraService.setLatestOnboardingInfo(loggingInfo);
// set resource status according to Provider's templateStatus
if (providerManager.get(infraService.getService().getResourceOrganisation()).getTemplateStatus().equals("approved template")) {
infraService.setStatus(vocabularyService.get("approved resource").getId());
LoggingInfo loggingInfoApproved = LoggingInfo.createLoggingInfoEntry(User.of(auth).getEmail(), User.of(auth).getFullName(), securityService.getRoleName(auth), LoggingInfo.Types.ONBOARD.getKey(), LoggingInfo.ActionType.APPROVED.getKey());
loggingInfoList.add(loggingInfoApproved);
// latestOnboardingInfo
infraService.setLatestOnboardingInfo(loggingInfoApproved);
} else {
infraService.setStatus(vocabularyService.get("pending resource").getId());
}
infraService.setMetadata(Metadata.updateMetadata(infraService.getMetadata(), User.of(auth).getFullName(), User.of(auth).getEmail()));
infraService = this.update(infraService, auth);
ResourceType infraResourceType = resourceTypeService.getResourceType("infra_service");
Resource resource = this.getResource(infraService.getId());
resource.setResourceType(resourceType);
resourceService.changeResourceType(resource, infraResourceType);
try {
infraService = infraServiceService.update(infraService, auth);
} catch (ResourceNotFoundException e) {
e.printStackTrace();
}
return infraService;
}
use of eu.openminted.registry.core.domain.Resource in project resource-catalogue by madgeek-arc.
the class ResourceManager method update.
@Override
public T update(T t, Authentication auth) {
Resource existing = whereID(t.getId(), true);
existing.setPayload(serialize(t));
existing.setResourceType(resourceType);
resourceService.updateResource(existing);
logger.debug("Updating Resource {}", t);
return t;
}
use of eu.openminted.registry.core.domain.Resource in project resource-catalogue by madgeek-arc.
the class ResourceManager method add.
@Override
public T add(T t, Authentication auth) {
if (exists(t)) {
throw new ResourceException(String.format("%s with id = '%s' already exists!", resourceType.getName(), t.getId()), HttpStatus.CONFLICT);
}
String serialized = serialize(t);
Resource created = new Resource();
created.setPayload(serialized);
created.setResourceType(resourceType);
resourceService.addResource(created);
logger.debug("Adding Resource {}", t);
return t;
}
Aggregations