All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.corbel.resources.rem.ImagePutRem Maven / Gradle / Ivy

There is a newer version: 1.44.0
Show newest version
package io.corbel.resources.rem;

import java.io.InputStream;
import java.util.Optional;

import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.corbel.lib.ws.api.error.ErrorResponseFactory;
import io.corbel.resources.rem.plugin.RestorRemNames;
import io.corbel.resources.rem.request.RequestParameters;
import io.corbel.resources.rem.request.ResourceId;
import io.corbel.resources.rem.request.ResourceParameters;
import io.corbel.resources.rem.service.ImageCacheService;

public class ImagePutRem extends ImageBaseRem {

    private static final Logger LOG = LoggerFactory.getLogger(ImagePutRem.class);
    private final ImageCacheService imageCacheService;

    public ImagePutRem(ImageCacheService imageCacheService) {
        this.imageCacheService = imageCacheService;
    }

    @Override
    public Response resource(String collection, ResourceId resourceId, RequestParameters requestParameters,
            Optional entity) {

        @SuppressWarnings("unchecked")
        Rem restorDeleteRem = remService.getRem(RestorRemNames.RESTOR_DELETE);

        @SuppressWarnings("unchecked")
        Rem restorPutRem = remService.getRem(RestorRemNames.RESTOR_PUT);

        if (restorDeleteRem == null || restorPutRem == null) {
            LOG.warn("RESTOR not found. May  be is needed to install it?");
            return ErrorResponseFactory.getInstance().notFound();
        }


        imageCacheService.removeFromCache(restorDeleteRem, requestParameters, resourceId, collection);
        restorPutRem.resource(collection, resourceId, requestParameters, entity);

        return Response.noContent().build();
    }

    @Override
    public Class getType() {
        return InputStream.class;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy