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

org.lockss.laaws.poller.api.AusApiDelegate Maven / Gradle / Ivy

package org.lockss.laaws.poller.api;

import org.springframework.core.io.Resource;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Optional;

/**
 * A delegate to be called by the {@link AusApiController}}.
 * Implement this interface with a {@link org.springframework.stereotype.Service} annotated class.
 */

public interface AusApiDelegate {

    Logger log = LoggerFactory.getLogger(AusApi.class);

    default Optional getObjectMapper() {
        return Optional.empty();
    }

    default Optional getRequest() {
        return Optional.empty();
    }

    default Optional getAcceptHeader() {
        return getRequest().map(r -> r.getHeader("Accept"));
    }

    /**
     * @see AusApi#getExportFiles
     */
    default ResponseEntity getExportFiles( String  auid,
         String  fileType,
         Boolean  isCompress,
         Boolean  isExcludeDirNodes,
         String  xlateFilenames,
         String  filePrefix,
         Long  maxSize,
         Integer  maxVersions) {
        if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
            if (getAcceptHeader().get().contains("")) {
                try {
                    return new ResponseEntity<>(getObjectMapper().get().readValue("", Resource.class), HttpStatus.NOT_IMPLEMENTED);
                } catch (IOException e) {
                    log.error("Couldn't serialize response for content type ", e);
                    return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
                }
            }
        } else {
            log.warn("ObjectMapper or HttpServletRequest not configured in default AusApi interface so no example is generated");
        }
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy