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

org.lockss.laaws.mdx.api.MdupdatesApiDelegate Maven / Gradle / Ivy

package org.lockss.laaws.mdx.api;

import org.lockss.laaws.mdx.model.ErrorResult;
import org.lockss.metadata.extractor.job.Job;
import org.lockss.laaws.mdx.model.JobPageInfo;
import org.lockss.util.rest.mdx.MetadataUpdateSpec;
import org.lockss.metadata.extractor.job.Status;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
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 jakarta.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.Optional;

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

public interface MdupdatesApiDelegate {

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

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

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

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

    /**
     * @see MdupdatesApi#deleteMdupdates
     */
    default ResponseEntity deleteMdupdates() {
        if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
            if (getAcceptHeader().get().contains("application/json")) {
                try {
                    return new ResponseEntity<>(getObjectMapper().get().readValue("0", Integer.class), HttpStatus.NOT_IMPLEMENTED);
                } catch (IOException e) {
                    log.error("Couldn't serialize response for content type application/json", e);
                    return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
                }
            }
        } else {
            log.warn("ObjectMapper or HttpServletRequest not configured in default MdupdatesApi interface so no example is generated");
        }
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }

    /**
     * @see MdupdatesApi#deleteMdupdatesJobid
     */
    default ResponseEntity deleteMdupdatesJobid( String  jobid) {
        if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
            if (getAcceptHeader().get().contains("application/json")) {
                try {
                    return new ResponseEntity<>(getObjectMapper().get().readValue("{\n  \"au\" : {\n    \"name\" : \"name\",\n    \"id\" : \"id\",\n    \"job\" : \"job\"\n  },\n  \"endDate\" : \"2000-01-23\",\n  \"description\" : \"description\",\n  \"id\" : \"id\",\n  \"creationDate\" : \"2000-01-23\",\n  \"startDate\" : \"2000-01-23\",\n  \"status\" : {\n    \"msg\" : \"msg\",\n    \"code\" : 0\n  }\n}", Job.class), HttpStatus.NOT_IMPLEMENTED);
                } catch (IOException e) {
                    log.error("Couldn't serialize response for content type application/json", e);
                    return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
                }
            }
        } else {
            log.warn("ObjectMapper or HttpServletRequest not configured in default MdupdatesApi interface so no example is generated");
        }
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }

    /**
     * @see MdupdatesApi#getMdupdates
     */
    default ResponseEntity getMdupdates( Integer  limit,
         String  continuationToken) {
        if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
            if (getAcceptHeader().get().contains("application/json")) {
                try {
                    return new ResponseEntity<>(getObjectMapper().get().readValue("{\n  \"jobs\" : [ {\n    \"au\" : {\n      \"name\" : \"name\",\n      \"id\" : \"id\",\n      \"job\" : \"job\"\n    },\n    \"endDate\" : \"2000-01-23\",\n    \"description\" : \"description\",\n    \"id\" : \"id\",\n    \"creationDate\" : \"2000-01-23\",\n    \"startDate\" : \"2000-01-23\",\n    \"status\" : {\n      \"msg\" : \"msg\",\n      \"code\" : 0\n    }\n  }, {\n    \"au\" : {\n      \"name\" : \"name\",\n      \"id\" : \"id\",\n      \"job\" : \"job\"\n    },\n    \"endDate\" : \"2000-01-23\",\n    \"description\" : \"description\",\n    \"id\" : \"id\",\n    \"creationDate\" : \"2000-01-23\",\n    \"startDate\" : \"2000-01-23\",\n    \"status\" : {\n      \"msg\" : \"msg\",\n      \"code\" : 0\n    }\n  } ],\n  \"pageInfo\" : {\n    \"curLink\" : \"curLink\",\n    \"resultsPerPage\" : 1,\n    \"totalCount\" : 6,\n    \"continuationToken\" : \"continuationToken\",\n    \"nextLink\" : \"nextLink\"\n  }\n}", JobPageInfo.class), HttpStatus.NOT_IMPLEMENTED);
                } catch (IOException e) {
                    log.error("Couldn't serialize response for content type application/json", e);
                    return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
                }
            }
        } else {
            log.warn("ObjectMapper or HttpServletRequest not configured in default MdupdatesApi interface so no example is generated");
        }
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }

    /**
     * @see MdupdatesApi#getMdupdatesJobid
     */
    default ResponseEntity getMdupdatesJobid( String  jobid) {
        if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
            if (getAcceptHeader().get().contains("application/json")) {
                try {
                    return new ResponseEntity<>(getObjectMapper().get().readValue("{\n  \"msg\" : \"msg\",\n  \"code\" : 0\n}", Status.class), HttpStatus.NOT_IMPLEMENTED);
                } catch (IOException e) {
                    log.error("Couldn't serialize response for content type application/json", e);
                    return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
                }
            }
        } else {
            log.warn("ObjectMapper or HttpServletRequest not configured in default MdupdatesApi interface so no example is generated");
        }
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }

    /**
     * @see MdupdatesApi#postMdupdates
     */
    default ResponseEntity postMdupdates( MetadataUpdateSpec  body,
         Boolean  force) {
        if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
            if (getAcceptHeader().get().contains("application/json")) {
                try {
                    return new ResponseEntity<>(getObjectMapper().get().readValue("{\n  \"au\" : {\n    \"name\" : \"name\",\n    \"id\" : \"id\",\n    \"job\" : \"job\"\n  },\n  \"endDate\" : \"2000-01-23\",\n  \"description\" : \"description\",\n  \"id\" : \"id\",\n  \"creationDate\" : \"2000-01-23\",\n  \"startDate\" : \"2000-01-23\",\n  \"status\" : {\n    \"msg\" : \"msg\",\n    \"code\" : 0\n  }\n}", Job.class), HttpStatus.NOT_IMPLEMENTED);
                } catch (IOException e) {
                    log.error("Couldn't serialize response for content type application/json", e);
                    return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
                }
            }
        } else {
            log.warn("ObjectMapper or HttpServletRequest not configured in default MdupdatesApi interface so no example is generated");
        }
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy