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

org.damap.base.rest.PersonResource Maven / Gradle / Ivy

There is a newer version: 4.3.0
Show newest version
package org.damap.base.rest;

import io.quarkus.security.Authenticated;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
import lombok.extern.jbosslog.JBossLog;
import org.damap.base.rest.base.ResultList;
import org.damap.base.rest.base.Search;
import org.damap.base.rest.base.resource.ResourceRead;
import org.damap.base.rest.base.resource.ResourceSearch;
import org.damap.base.rest.dmp.domain.ContributorDO;
import org.damap.base.rest.persons.PersonService;

/** PersonResource class. */
@Path("/api/persons")
@Authenticated
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@JBossLog
public class PersonResource implements ResourceRead, ResourceSearch {

  @Inject PersonServiceBroker personServiceBroker;

  /** {@inheritDoc} */
  @Override
  public ContributorDO read(String id, UriInfo uriInfo) {
    var queryParams = uriInfo.getQueryParameters();
    log.info("Return person details for id=" + id + " and query=" + queryParams.toString());
    PersonService searchService = personServiceBroker.getServiceFromQueryParams(queryParams);

    ContributorDO result = null;
    if (searchService != null) {
      result = searchService.read(id, queryParams);
    }

    return result;
  }

  /** {@inheritDoc} */
  @Override
  public ResultList search(UriInfo uriInfo) {
    var queryParams = uriInfo.getQueryParameters();
    log.info("Return person list for query=" + queryParams.toString());

    PersonService searchService = personServiceBroker.getServiceFromQueryParams(queryParams);
    Search search = Search.fromMap(queryParams);

    ResultList result = ResultList.fromItemsAndSearch(null, search);

    if (searchService != null) {
      result = searchService.search(queryParams);
    }

    return result;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy