Search in sources :

Example 21 with ServiceUnavailableException

use of javax.ws.rs.ServiceUnavailableException in project robozonky by RoboZonky.

the class SessionTest method investmentFailed.

@Test
void investmentFailed() {
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
    final Authenticated auth = mockAuthentication(z);
    final RecommendedLoan r = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(200).get();
    final Exception thrown = new ServiceUnavailableException();
    final Investor p = mock(Investor.class);
    doThrow(thrown).when(p).invest(eq(r), anyBoolean());
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Session t = new Session(portfolio, Collections.emptySet(), p, auth);
    assertThatThrownBy(() -> t.invest(r)).isSameAs(thrown);
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) Zonky(com.github.robozonky.common.remote.Zonky) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 22 with ServiceUnavailableException

use of javax.ws.rs.ServiceUnavailableException in project dataverse by IQSS.

the class Meta method variable.

@Path("variable/{varId}")
@GET
@Produces({ "application/xml" })
public String variable(@PathParam("varId") Long varId, @QueryParam("exclude") String exclude, @QueryParam("include") String include, @Context HttpHeaders header, @Context HttpServletResponse response) /*throws NotFoundException, ServiceUnavailableException, PermissionDeniedException, AuthorizationRequiredException*/
{
    String retValue = "";
    ByteArrayOutputStream outStream = null;
    try {
        outStream = new ByteArrayOutputStream();
        ddiExportService.exportDataVariable(varId, outStream, exclude, include);
    } catch (Exception e) {
        // metadata record requested. We simply return an empty string.
        return retValue;
    }
    retValue = outStream.toString();
    response.setHeader("Access-Control-Allow-Origin", "*");
    return retValue;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) NotFoundException(javax.ws.rs.NotFoundException) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 23 with ServiceUnavailableException

use of javax.ws.rs.ServiceUnavailableException in project dataverse by IQSS.

the class Access method tabularDatafileMetadataPreprocessed.

/*
     * "Preprocessed data" metadata format:
     * (this was previously provided as a "format conversion" option of the 
     * file download form of the access API call)
     */
@Path("datafile/{fileId}/metadata/preprocessed")
@GET
@Produces({ "text/xml" })
public DownloadInstance tabularDatafileMetadataPreprocessed(@PathParam("fileId") Long fileId, @QueryParam("key") String apiToken, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) throws ServiceUnavailableException {
    DataFile df = dataFileService.find(fileId);
    if (df == null) {
        logger.warning("Access: datafile service could not locate a DataFile object for id " + fileId + "!");
        throw new NotFoundException();
    }
    if (apiToken == null || apiToken.equals("")) {
        apiToken = headers.getHeaderString(API_KEY_HEADER);
    }
    // This will throw a ForbiddenException if access isn't authorized:
    checkAuthorization(df, apiToken);
    DownloadInfo dInfo = new DownloadInfo(df);
    if (df.isTabularData()) {
        dInfo.addServiceAvailable(new OptionalAccessService("preprocessed", "application/json", "format=prep", "Preprocessed data in JSON"));
    } else {
        throw new ServiceUnavailableException("Preprocessed Content Metadata requested on a non-tabular data file.");
    }
    DownloadInstance downloadInstance = new DownloadInstance(dInfo);
    if (downloadInstance.isDownloadServiceSupported("format", "prep")) {
        logger.fine("Preprocessed data for tabular file " + fileId);
    }
    response.setHeader("Access-Control-Allow-Origin", "*");
    return downloadInstance;
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) NotFoundException(javax.ws.rs.NotFoundException) OptionalAccessService(edu.harvard.iq.dataverse.dataaccess.OptionalAccessService) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 24 with ServiceUnavailableException

use of javax.ws.rs.ServiceUnavailableException in project dataverse by IQSS.

the class Access method dataVariableMetadataDDI.

@Path("variable/{varId}/metadata/ddi")
@GET
@Produces({ "application/xml" })
public String dataVariableMetadataDDI(@PathParam("varId") Long varId, @QueryParam("exclude") String exclude, @QueryParam("include") String include, @Context HttpHeaders header, @Context HttpServletResponse response) /*throws NotFoundException, ServiceUnavailableException, PermissionDeniedException, AuthorizationRequiredException*/
{
    String retValue = "";
    ByteArrayOutputStream outStream = null;
    try {
        outStream = new ByteArrayOutputStream();
        ddiExportService.exportDataVariable(varId, outStream, exclude, include);
    } catch (Exception e) {
        // metadata record requested. We simply return an empty string.
        return retValue;
    }
    retValue = outStream.toString();
    response.setHeader("Access-Control-Allow-Origin", "*");
    return retValue;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) WebApplicationException(javax.ws.rs.WebApplicationException) ForbiddenException(javax.ws.rs.ForbiddenException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 25 with ServiceUnavailableException

use of javax.ws.rs.ServiceUnavailableException in project dataverse by IQSS.

the class Access method datafileBundle.

// @EJB
// TODO:
// versions? -- L.A. 4.0 beta 10
@Path("datafile/bundle/{fileId}")
@GET
@Produces({ "application/zip" })
public BundleDownloadInstance datafileBundle(@PathParam("fileId") Long fileId, @QueryParam("gbrecs") Boolean gbrecs, @QueryParam("key") String apiToken, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) /*throws NotFoundException, ServiceUnavailableException, PermissionDeniedException, AuthorizationRequiredException*/
{
    DataFile df = dataFileService.find(fileId);
    GuestbookResponse gbr = null;
    if (df == null) {
        logger.warning("Access: datafile service could not locate a DataFile object for id " + fileId + "!");
        throw new NotFoundException();
    }
    if (apiToken == null || apiToken.equals("")) {
        apiToken = headers.getHeaderString(API_KEY_HEADER);
    }
    // This will throw a ForbiddenException if access isn't authorized:
    checkAuthorization(df, apiToken);
    if (gbrecs == null && df.isReleased()) {
        // Write Guestbook record if not done previously and file is released
        User apiTokenUser = findAPITokenUser(apiToken);
        gbr = guestbookResponseService.initAPIGuestbookResponse(df.getOwner(), df, session, apiTokenUser);
        guestbookResponseService.save(gbr);
    }
    DownloadInfo dInfo = new DownloadInfo(df);
    BundleDownloadInstance downloadInstance = new BundleDownloadInstance(dInfo);
    FileMetadata fileMetadata = df.getFileMetadata();
    DatasetVersion datasetVersion = df.getOwner().getLatestVersion();
    downloadInstance.setFileCitationEndNote(datasetService.createCitationXML(datasetVersion, fileMetadata));
    downloadInstance.setFileCitationRIS(datasetService.createCitationRIS(datasetVersion, fileMetadata));
    downloadInstance.setFileCitationBibtex(new BibtexCitation(datasetVersion).toString());
    ByteArrayOutputStream outStream = null;
    outStream = new ByteArrayOutputStream();
    try {
        ddiExportService.exportDataFile(fileId, outStream, null, null);
        downloadInstance.setFileDDIXML(outStream.toString());
    } catch (Exception ex) {
    // if we can't generate the DDI, it's ok;
    // we'll just generate the bundle without it.
    }
    return downloadInstance;
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) GuestUser(edu.harvard.iq.dataverse.authorization.users.GuestUser) GuestbookResponse(edu.harvard.iq.dataverse.GuestbookResponse) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) NotFoundException(javax.ws.rs.NotFoundException) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) BibtexCitation(edu.harvard.iq.dataverse.BibtexCitation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) WebApplicationException(javax.ws.rs.WebApplicationException) ForbiddenException(javax.ws.rs.ForbiddenException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ServiceUnavailableException (javax.ws.rs.ServiceUnavailableException)40 NotFoundException (javax.ws.rs.NotFoundException)16 GET (javax.ws.rs.GET)13 Path (javax.ws.rs.Path)13 Produces (javax.ws.rs.Produces)13 WebApplicationException (javax.ws.rs.WebApplicationException)13 BadRequestException (javax.ws.rs.BadRequestException)12 Response (javax.ws.rs.core.Response)12 ForbiddenException (javax.ws.rs.ForbiddenException)9 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)8 DataFile (edu.harvard.iq.dataverse.DataFile)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 IOException (java.io.IOException)7 ClientErrorException (javax.ws.rs.ClientErrorException)7 ServerErrorException (javax.ws.rs.ServerErrorException)7 Test (org.junit.Test)6 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)4 RedirectionException (javax.ws.rs.RedirectionException)4 CircuitBreakerConfiguration (com.oracle.bmc.circuitbreaker.CircuitBreakerConfiguration)3 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)3