com.sun.jersey.api.NotFoundException Java Examples

The following examples show how to use com.sun.jersey.api.NotFoundException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SystemOfRecordRolesResource.java    From openregistry with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> findPersonAndRoleOrThrowNotFoundException(final String sorSourceId, final String sorPersonId, final String sorRoleId) {
    //Poor simulation of Tuple 'pair'. Oh, well
    final Map<String, Object> ret = new HashMap<String, Object>(2);
    final SorPerson sorPerson = this.personService.findBySorIdentifierAndSource(sorSourceId, sorPersonId);
    if (sorPerson == null) {
        //HTTP 404
        throw new NotFoundException(
                String.format("The person resource identified by [/sor/%s/people/%s] URI does not exist.",
                        sorSourceId, sorPersonId));
    }
    if (sorRoleId != null) {
        final SorRole sorRole = sorPerson.findSorRoleBySorRoleId(sorRoleId);
        if (sorRole == null) {
            throw new NotFoundException(
                    String.format("The role resource identified by [/sor/%s/people/%s/roles/%s] URI does not exist.",
                            sorSourceId, sorPersonId, sorRoleId));
        }
        ret.put("role", sorRole);
    }
    ret.put("person", sorPerson);
    return ret;
}
 
Example #2
Source File: DownloadRequestServiceImpl.java    From occurrence with Apache License 2.0 6 votes vote down vote up
@Override
public void cancel(String downloadKey) {
  try {
    Download download = occurrenceDownloadService.get(downloadKey);
    if (download != null) {
      if (RUNNING_STATUSES.contains(download.getStatus())) {
        updateDownloadStatus(download, Download.Status.CANCELLED);
        client.kill(DownloadUtils.downloadToWorkflowId(downloadKey));
        LOG.info("Download {} cancelled", downloadKey);
      }
    } else {
      throw new NotFoundException(String.format("Download %s not found", downloadKey));
    }
  } catch (OozieClientException e) {
    throw new ServiceUnavailableException("Failed to cancel download " + downloadKey, e);
  }
}
 
Example #3
Source File: TitusExceptionMapper.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private String toStandardHttpErrorMessage(int status, Throwable cause) {
    // Do not use message from Jersey exceptions, as we can do better
    if (cause instanceof ParamException) {
        ParamException pe = (ParamException) cause;
        return "invalid parameter " + pe.getParameterName() + "=" + pe.getDefaultStringValue() + " of type " + pe.getParameterType();
    }
    if (cause instanceof NotFoundException) {
        NotFoundException nfe = (NotFoundException) cause;
        return "resource not found: " + nfe.getNotFoundUri();
    }
    if (cause.getMessage() != null) {
        return cause.getMessage();
    }
    try {
        return Status.fromStatusCode(status).getReasonPhrase();
    } catch (Exception e) {
        return "HTTP error " + status;
    }
}
 
Example #4
Source File: SystemOfRecordRolesResource.java    From openregistry with Apache License 2.0 6 votes vote down vote up
@DELETE
@Path("{sorRoleId}")
public Response deleteRole(@PathParam("sorSourceId") final String sorSourceId,
                           @PathParam("sorPersonId") final String sorPersonId,
                           @PathParam("sorRoleId") final String sorRoleId,
                           @QueryParam("mistake") @DefaultValue("false") final boolean mistake,
                           @QueryParam("terminationType") @DefaultValue("UNSPECIFIED") final String terminationType) {

    final Map<String, Object> personAndRole = findPersonAndRoleOrThrowNotFoundException(sorSourceId, sorPersonId, sorRoleId);
    final SorPerson sorPerson = (SorPerson) personAndRole.get("person");
    final SorRole sorRole = (SorRole) personAndRole.get("role");
    try {
        //TODO: need to encapsulate the lookups behind the service API
        if (!this.personService.deleteSystemOfRecordRole(sorPerson, sorRole, mistake, terminationType)) {
            throw new WebApplicationException(
                    new RuntimeException(String.format("Unable to Delete SorRole for SoR [ %s ] with ID [ %s ] and Role ID [ %s ]", sorSourceId, sorPersonId, sorRoleId)), 500);
        }
        //HTTP 204
        logger.debug("The SOR Person role has been successfully DELETEd");
        return null;
    }
    catch (final PersonNotFoundException e) {
        throw new NotFoundException(String.format("The system of record role resource identified by /sor/%s/people/%s/%s URI does not exist",
                sorSourceId, sorPersonId, sorRoleId));
    }
}
 
Example #5
Source File: EndpointMutatorTest.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Test(expected = NotFoundException.class)
public void testNoPathSegments() throws URISyntaxException {
    // Test /api/rest with no additional path segments.
    SLIPrincipal principle = mock(SLIPrincipal.class);
    ClientToken clientToken = mock(ClientToken.class);
    when(clientToken.getClientId()).thenReturn("theAppId");
    OAuth2Authentication auth = mock(OAuth2Authentication.class);
    when(auth.getPrincipal()).thenReturn(principle);
    when(auth.getClientAuthentication()).thenReturn(clientToken);

    ContainerRequest request = mock(ContainerRequest.class);
    List<PathSegment> segments = Collections.emptyList();
    when(request.getPathSegments()).thenReturn(segments);
    when(request.getMethod()).thenReturn("GET");
    when(request.getRequestUri()).thenReturn(new URI("http://not.valid.inbloom.org"));
    
    endpointMutator.mutateURI(auth, request);
}
 
Example #6
Source File: SystemOfRecordPeopleResource.java    From openregistry with Apache License 2.0 6 votes vote down vote up
@DELETE
@Path("{sorPersonId}")
public Response deletePerson(@PathParam("sorSourceId") final String sorSourceId,
                             @PathParam("sorPersonId") final String sorPersonId,
                             @QueryParam("mistake") @DefaultValue("false") final boolean mistake,
                             @QueryParam("terminationType") @DefaultValue("UNSPECIFIED") final String terminationType) {
    try {
        if (!this.personService.deleteSystemOfRecordPerson(sorSourceId, sorPersonId, mistake, terminationType)) {
            throw new WebApplicationException(
                    new RuntimeException(String.format("Unable to Delete SorPerson for SoR [ %s ] with ID [ %s ]", sorSourceId, sorPersonId)), 500);
        }
        //HTTP 204
        logger.debug("The SOR Person resource has been successfully DELETEd");
        return null;
    }
    catch (final PersonNotFoundException e) {
        throw new NotFoundException(String.format("The system of record person resource identified by /sor/%s/people/%s URI does not exist",
                sorSourceId, sorPersonId));
    }
}
 
Example #7
Source File: SystemOfRecordPeopleResource.java    From openregistry with Apache License 2.0 6 votes vote down vote up
@DELETE
@Path("{sorPersonId}")
public Response deletePerson(@PathParam("sorSourceId") final String sorSourceId,
                             @PathParam("sorPersonId") final String sorPersonId,
                             @QueryParam("mistake") @DefaultValue("false") final boolean mistake,
                             @QueryParam("terminationType") @DefaultValue("UNSPECIFIED") final String terminationType) {
    try {
        if (!this.personService.deleteSystemOfRecordPerson(sorSourceId, sorPersonId, mistake, terminationType)) {
            throw new WebApplicationException(
                    new RuntimeException(String.format("Unable to Delete SorPerson for SoR [ %s ] with ID [ %s ]", sorSourceId, sorPersonId)), 500);
        }
        //HTTP 204
        logger.debug("The SOR Person resource has been successfully DELETEd");
        return null;
    }
    catch (final PersonNotFoundException e) {
        throw new NotFoundException(String.format("The system of record person resource identified by /sor/%s/people/%s URI does not exist",
                sorSourceId, sorPersonId));
    }
}
 
Example #8
Source File: IdCardResource.java    From openregistry with Apache License 2.0 6 votes vote down vote up
/**
 * a method to get xml representation of primary id card attached to a person
 */
@GET
@Produces({MediaType.APPLICATION_XML})
@Consumes({MediaType.TEXT_XML})
public IdCardRepresentation getIdCard(@PathParam("personId") String personId){
    final Person person = findPersonOrThrowNotFoundException(personId);
    if( person.getPrimaryIdCard()==null){
        //HTTP 404
        logger.info("ID card Not not found.");
        throw new NotFoundException(
                String.format("The primary Id card for person identified by /people/%s URI does not exist",
                        personId));
    }
     return buildIdCardRepresentation(person,person.getPrimaryIdCard());

}
 
Example #9
Source File: IdCardResource.java    From openregistry with Apache License 2.0 6 votes vote down vote up
/**
 * this method  deletes (expire a card)
 */
@DELETE
@Produces({MediaType.TEXT_XML})
@Consumes({MediaType.TEXT_XML})
public void deleteIdCard(@PathParam("personId") String personId){
    final Person person = findPersonOrThrowNotFoundException(personId);

    if( person.getPrimaryIdCard()==null){
        //HTTP 404
        logger.info("ID card Not not found.");
        throw new NotFoundException(
                String.format("The primary Id card for person identified by /people/%s URI does not exist",
                        personId));
    }
    if( person.getPrimaryIdCard().getExpirationDate()!=null){
        //HTTP 404
        logger.info("Unexpired Primary ID card Not not found.");
        throw new NotFoundException(
                String.format("Unexpired primary Id card for person identified by /people/%s URI does not exist",
                        personId));
    }
        //http 204
    idCardService.expireIdCard(person);
}
 
Example #10
Source File: IdCardResource.java    From openregistry with Apache License 2.0 6 votes vote down vote up
/**
 * this method updates the existing card with the proximith number
 * It id idempotent ..so it can be safely invoked as many times as needed
 * @param personId personID
 * @param proximityNumber  proximityNumber to be assigned
 * @return
 */
 @PUT
 @Produces({MediaType.APPLICATION_XML})
 @Consumes({MediaType.TEXT_XML})
 @Path("{proximityNumber}")
public IdCardRepresentation assignProximityNumber(@PathParam("personId") String personId,@PathParam("proximityNumber") String proximityNumber){
     final Person person = findPersonOrThrowNotFoundException(personId);
     if( person.getPrimaryIdCard()==null){
         //HTTP 404
         logger.info("ID card Not not found.");
         throw new NotFoundException(
                 String.format("The primary Id card for person identified by /people/%s URI does not exist",
                          personId));
     }
     if(proximityNumber==null|| proximityNumber.equals("")){
              //HTTP 400
         throw new WebApplicationException(Response.Status.BAD_REQUEST);
     }
       return this.buildIdCardRepresentation(person,   idCardService.assignProximityNumber(person,proximityNumber).getTargetObject());

}
 
Example #11
Source File: IdCardResource.java    From openregistry with Apache License 2.0 5 votes vote down vote up
private Person findPersonOrThrowNotFoundException( final String personId) {
    logger.info(String.format("Searching for a person with  {personIdType:%s, personId:%s} ...", idBasedOn, personId));
    final Person person = this.personService.findPersonByIdentifier(idBasedOn, personId);
    if (person == null) {
        //HTTP 404
        logger.info("Person is not found.");
        throw new NotFoundException(
                String.format("The person identified by /people/%s URI does not exist",
                        personId));
    }
    return person;
}
 
Example #12
Source File: SystemOfRecordRolesResource.java    From openregistry with Apache License 2.0 5 votes vote down vote up
private void setOrganizationalUnit(SorRole sorRole, String organizationalUnitCode) {
    try {
        OrganizationalUnit org = referenceRepository.getOrganizationalUnitByCode(organizationalUnitCode);
        sorRole.setOrganizationalUnit(org);
    }
    catch (Exception ex) {
        throw new NotFoundException(
        String.format("The department identified by [%s] does not exist", organizationalUnitCode));
    }
}
 
Example #13
Source File: SystemOfRecordRolesResource.java    From openregistry with Apache License 2.0 5 votes vote down vote up
private void setSystemOfRecord(SorRole sorRole, String systemOfRecord) {
    try {
        SystemOfRecord sor = referenceRepository.findSystemOfRecord(systemOfRecord);
        sorRole.setSystemOfRecord(sor);
    }
    catch (Exception ex) {
        throw new NotFoundException(
        String.format("The system or record identified by [%s] does not exist", systemOfRecord));
    }
}
 
Example #14
Source File: EmailResource.java    From openregistry with Apache License 2.0 5 votes vote down vote up
private LocalData extractProcessingDataFrom(String emailType, String identifierType, String identifier, String affiliation,
                                            String sor) {

    LocalData d = new LocalData();
    Response r = validateRequiredRequestQueryParams(emailType, identifierType, identifier, affiliation, sor);
    if (r != null) {
        d.response = r;
        return d;
    }

    Type validatedType = this.referenceRepository.findValidType(Type.DataTypes.ADDRESS, emailType);
    if (validatedType == null) {
        //HTTP 400
        d.response = Response.status(Response.Status.BAD_REQUEST)
                .entity(new ErrorsResponseRepresentation(Arrays.asList("The provided email type is invalid.")))
                .type(MediaType.APPLICATION_XML).build();
        return d;
    }
    d.emailAddressType = validatedType;

    validatedType = this.referenceRepository.findValidType(Type.DataTypes.AFFILIATION, affiliation);
    if (validatedType == null) {
        //HTTP 400
        d.response = Response.status(Response.Status.BAD_REQUEST)
                .entity(new ErrorsResponseRepresentation(Arrays.asList("The provided affiliation type is invalid.")))
                .type(MediaType.APPLICATION_XML).build();
        return d;
    }
    d.affiliationType = validatedType;

    SorPerson sorPerson = this.personService.findByIdentifierAndSource(identifierType, identifier, sor);
    if (sorPerson == null) {
        //HTTP 404
        throw new NotFoundException("The person cannot be found in the registry or is not attached to the provided SOR");
    }
    d.sorPerson = sorPerson;
    return d;
}
 
Example #15
Source File: EmailResource.java    From openregistry with Apache License 2.0 5 votes vote down vote up
private LocalData2 extractProcessingDataForAllEmails(String emailType,String identifierType, String identifier) {

        LocalData2 d = new LocalData2();
        Response r = validateRequiredRequestQueryParams(emailType, identifierType, identifier);
        if (r != null) {
            d.response = r;
            return d;
        }

        Type validatedType = this.referenceRepository.findValidType(Type.DataTypes.ADDRESS, emailType);
        if (validatedType == null) {
            //HTTP 400
            d.response = Response.status(Response.Status.BAD_REQUEST)
                    .entity(new ErrorsResponseRepresentation(Arrays.asList("The provided email type is invalid.")))
                    .type(MediaType.APPLICATION_XML).build();
            return d;
        }
        d.emailAddressType = validatedType;

        //No SoR for this request
        //SorPerson sorPerson = this.personService.findByIdentifierAndSource(identifierType, identifier, null);
        List<SorPerson> sorPeople = this.personService.findByIdentifier(identifierType, identifier);
        if (sorPeople == null) {
            //HTTP 404
            throw new NotFoundException("The person cannot be found in the registry or is not attached to the provided SOR");
        }
        d.sorPeople = sorPeople;
        return d;
    }
 
Example #16
Source File: DownloadRequestServiceImpl.java    From occurrence with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public File getResultFile(String downloadKey) {
  String filename;

  // avoid check for download in the registry if we have secret non download files with a magic prefix!
  if (downloadKey == null || !downloadKey.toLowerCase().startsWith(NON_DOWNLOAD_PREFIX)) {
    Download d = occurrenceDownloadService.get(downloadKey);

    if (d == null) {
      throw new NotFoundException("Download " + downloadKey + " doesn't exist");
    }

    if (d.getStatus() == Download.Status.FILE_ERASED) {
      Response gone = Response
        .status(Response.Status.GONE)
        .entity("Download " + downloadKey + " has been erased\n")
        .type("text/plain")
        .build();
      throw new WebApplicationException(gone);
    }

    if (!d.isAvailable()) {
      throw new NotFoundException("Download " + downloadKey + " is not ready yet");
    }

    filename = getDownloadFilename(d);
  } else {
    filename = downloadKey + ".zip";
  }

  File localFile = new File(downloadMount, filename);
  if (localFile.canRead()) {
    return localFile;
  } else {
    throw new IllegalStateException(
      "Unable to read download " + downloadKey + " from " + localFile.getAbsolutePath());
  }
}
 
Example #17
Source File: SystemOfRecordPeopleResource.java    From openregistry with Apache License 2.0 5 votes vote down vote up
private SorPerson findPersonOrThrowNotFoundException(final String sorSourceId, final String sorPersonId) {
    final SorPerson sorPerson = this.personService.findBySorIdentifierAndSource(sorSourceId, sorPersonId);
    if (sorPerson == null) {
        //HTTP 404
        throw new NotFoundException(
                String.format("The person resource identified by [/sor/%s/people/%s] URI does not exist.",
                        sorSourceId, sorPersonId));
    }
    return sorPerson;
}
 
Example #18
Source File: ActivationKeyFactoryResource.java    From openregistry with Apache License 2.0 5 votes vote down vote up
@POST
public Response generateNewActivationKey(@PathParam("personIdType") final String personIdType, @PathParam("personId") final String personId) {
    try {
        String activationKey = this.activationService.generateActivationKey(personIdType, personId).asString();
        //HTTP 201
        return Response.created(buildActivationProcessorResourceUri(activationKey)).build();
    } catch (final PersonNotFoundException ex) {
        throw new NotFoundException(String.format("The person resource identified by /people/%s/%s URI does not exist", personIdType, personId));
    }
}
 
Example #19
Source File: PeopleResource.java    From openregistry with Apache License 2.0 5 votes vote down vote up
private Person findPersonOrThrowNotFoundException(final String personIdType, final String personId) {
    logger.info(String.format("Searching for a person with  {personIdType:%s, personId:%s} ...", personIdType, personId));
    final Person person = this.personService.findPersonByIdentifier(personIdType, personId);
    if (person == null) {
        //HTTP 404
        logger.info("Person is not found.");
        throw new NotFoundException(
                String.format("The person resource identified by /people/%s/%s URI does not exist",
                        personIdType, personId));
    }
    return person;
}
 
Example #20
Source File: ArchiveRepositoriesResource.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
@Path("/{repositoryId}")
public ArchiveRepositoryResource getScriptRepo(@PathParam("repositoryId") String repositoryId) {
    ArchiveRepository repository = repositories.get(repositoryId);
    if (repository == null) {
        throw new NotFoundException("no such repository '" + repositoryId + "'");
    }
    return new ArchiveRepositoryResource(repository);
}
 
Example #21
Source File: RuleResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/rules/{id}")
public Response getRule(
        @PathParam("id") final String ruleId,
        @QueryParam("processorId") final String processorId,
        @DefaultValue("false") @QueryParam("verbose") final Boolean verbose) {

    // get the web context
    final NiFiWebConfigurationContext configurationContext = (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");

    // build the web context config
    final NiFiWebRequestContext requestContext = getRequestContext(processorId);

    // load the criteria and get the rule
    final Criteria criteria = getCriteria(configurationContext, requestContext);
    final Rule rule = criteria.getRule(ruleId);

    if (rule == null) {
        throw new NotFoundException();
    }

    // convert to a dto
    final RuleDTO ruleDto = DtoFactory.createRuleDTO(rule);

    // prune if appropriate
    if (!verbose) {
        ruleDto.setConditions(null);
        ruleDto.setActions(null);
    }

    // create the response entity
    final RuleEntity responseEntity = new RuleEntity();
    responseEntity.setProcessorId(processorId);
    responseEntity.setRule(ruleDto);

    // generate the response
    final ResponseBuilder response = Response.ok(responseEntity);
    return noCache(response).build();
}
 
Example #22
Source File: JobResource.java    From ecs-sync with Apache License 2.0 5 votes vote down vote up
@GET
@Path("{jobId}/control")
@Produces(MediaType.APPLICATION_XML)
public JobControl getControl(@PathParam("jobId") int jobId) {
    JobControl jobControl = SyncJobService.getInstance().getJobControl(jobId);
    if (jobControl == null) throw new NotFoundException(); // job not found
    return jobControl;
}
 
Example #23
Source File: RuleResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@DELETE
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/rules/{id}")
public Response deleteRule(
        @PathParam("id") final String ruleId,
        @QueryParam("processorId") final String processorId,
        @QueryParam("clientId") final String clientId,
        @QueryParam("revision") final Long revision) {

    // get the web context
    final NiFiWebConfigurationContext configurationContext = (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");

    // build the web context config
    final NiFiWebConfigurationRequestContext requestContext = getConfigurationRequestContext(processorId, revision, clientId);

    // load the criteria and get the rule
    final Criteria criteria = getCriteria(configurationContext, requestContext);
    final Rule rule = criteria.getRule(ruleId);

    if (rule == null) {
        throw new NotFoundException();
    }

    // delete the rule
    criteria.deleteRule(rule);

    // save the criteria
    saveCriteria(requestContext, criteria);

    // create the response entity
    final RulesEntity responseEntity = new RulesEntity();
    responseEntity.setClientId(clientId);
    responseEntity.setRevision(revision);
    responseEntity.setProcessorId(processorId);

    // generate the response
    final ResponseBuilder response = Response.ok(responseEntity);
    return noCache(response).build();
}
 
Example #24
Source File: NotFoundExceptionMapper.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Response toResponse(NotFoundException exception) {
    // log the error
    logger.info(String.format("%s. Returning %s response.", exception, Response.Status.NOT_FOUND));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, exception);
    }

    return Responses.notFound().entity("The specified resource could not be found.").type("text/plain").build();
}
 
Example #25
Source File: Jersey1ApiExceptionHandlerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void toResponseReturnsCorrectResponseForJerseyWebApplicationException() {

    NotFoundException exception = new NotFoundException("uri not found!");
    Response actualResponse = handlerSpy.toResponse(exception);

    Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, actualResponse.getStatus());
}
 
Example #26
Source File: Jersey1WebApplicationExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@DataProvider
public static Object[][] dataProviderForShouldHandleException() {
    return new Object[][] {
        { new NotFoundException(), testProjectApiErrors.getNotFoundApiError() },
        { mock(ParamException.URIParamException.class), testProjectApiErrors.getNotFoundApiError() },
        { mock(ParamException.class), testProjectApiErrors.getMalformedRequestApiError() },
        { new WebApplicationException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE), testProjectApiErrors.getUnsupportedMediaTypeApiError() },
        { new WebApplicationException(HttpServletResponse.SC_METHOD_NOT_ALLOWED), testProjectApiErrors.getMethodNotAllowedApiError() },
        { new WebApplicationException(HttpServletResponse.SC_UNAUTHORIZED), testProjectApiErrors.getUnauthorizedApiError() },
        { new WebApplicationException(HttpServletResponse.SC_NOT_ACCEPTABLE), testProjectApiErrors.getNoAcceptableRepresentationApiError() },
        { mock(JsonProcessingException.class), testProjectApiErrors.getMalformedRequestApiError() }
    };
}
 
Example #27
Source File: JobResource.java    From ecs-sync with Apache License 2.0 5 votes vote down vote up
@GET
@Path("{jobId}")
@Produces(MediaType.APPLICATION_XML)
public SyncConfig get(@PathParam("jobId") int jobId) {
    SyncConfig syncConfig = SyncJobService.getInstance().getJob(jobId);
    if (syncConfig == null) throw new NotFoundException(); // job not found
    return syncConfig;
}
 
Example #28
Source File: PeopleResource.java    From openregistry with Apache License 2.0 5 votes vote down vote up
private Person findPersonOrThrowNotFoundException(final String personIdType, final String personId) {
    logger.info(String.format("Searching for a person with  {personIdType:%s, personId:%s} ...", personIdType, personId));
    final Person person = this.personService.findPersonByIdentifier(personIdType, personId);
    if (person == null) {
        //HTTP 404
        logger.info("Person is not found.");
        throw new NotFoundException(
                String.format("The person resource identified by /people/%s/%s URI does not exist",
                        personIdType, personId));
    }
    return person;
}
 
Example #29
Source File: JobResource.java    From ecs-sync with Apache License 2.0 5 votes vote down vote up
@GET
@Path("{jobId}/progress")
@Produces(MediaType.APPLICATION_XML)
public SyncProgress getProgress(@PathParam("jobId") int jobId) {
    SyncProgress syncProgress = SyncJobService.getInstance().getProgress(jobId);
    if (syncProgress == null) throw new NotFoundException(); // job not found
    return syncProgress;
}
 
Example #30
Source File: JobResource.java    From ecs-sync with Apache License 2.0 5 votes vote down vote up
@GET
@Path("{jobId}/errors.csv")
@Produces("text/csv")
public Response getErrors(@PathParam("jobId") int jobId) throws IOException {
    if (!SyncJobService.getInstance().jobExists(jobId)) throw new NotFoundException(); // job not found

    ErrorReportWriter reportWriter = new ErrorReportWriter(SyncJobService.getInstance().getSyncErrors(jobId));

    Thread writerThread = new Thread(reportWriter);
    writerThread.setDaemon(true);
    writerThread.start();

    return Response.ok(reportWriter.getReadStream()).build();
}