Search in sources :

Example 11 with Resource

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;
}
Also used : ArrayList(java.util.ArrayList) Resource(eu.openminted.registry.core.domain.Resource) ResourceType(eu.openminted.registry.core.domain.ResourceType) ResourceNotFoundException(eu.openminted.registry.core.exception.ResourceNotFoundException) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 12 with Resource

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;
}
Also used : Resource(eu.openminted.registry.core.domain.Resource)

Example 13 with Resource

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;
}
Also used : Resource(eu.openminted.registry.core.domain.Resource) ResourceException(eu.einfracentral.exception.ResourceException)

Aggregations

Resource (eu.openminted.registry.core.domain.Resource)13 CacheEvict (org.springframework.cache.annotation.CacheEvict)10 ResourceException (eu.einfracentral.exception.ResourceException)4 ResourceType (eu.openminted.registry.core.domain.ResourceType)4 ResourceNotFoundException (eu.openminted.registry.core.exception.ResourceNotFoundException)4 ArrayList (java.util.ArrayList)4 CACHE_VISITS (eu.einfracentral.config.CacheConfig.CACHE_VISITS)1 Event (eu.einfracentral.domain.Event)1 InfraService (eu.einfracentral.domain.InfraService)1 ProviderBundle (eu.einfracentral.domain.ProviderBundle)1 Service (eu.einfracentral.domain.Service)1 MapValues (eu.einfracentral.dto.MapValues)1 PlaceCount (eu.einfracentral.dto.PlaceCount)1 Value (eu.einfracentral.dto.Value)1 InfraServiceManager (eu.einfracentral.registry.manager.InfraServiceManager)1 ProviderService (eu.einfracentral.registry.service.ProviderService)1 VocabularyService (eu.einfracentral.registry.service.VocabularyService)1 AnalyticsService (eu.einfracentral.service.AnalyticsService)1 StatisticsService (eu.einfracentral.service.StatisticsService)1 FacetFilter (eu.openminted.registry.core.domain.FacetFilter)1