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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations