use of org.intermine.webservice.server.exceptions.BadRequestException in project intermine by intermine.
the class GenomicRegionSearchService method makeList.
@Override
protected void makeList(ListInput input, String type, Profile profile, Set<String> temporaryBagNamesAccumulator) throws Exception {
if (input.doReplace()) {
ListServiceUtils.ensureBagIsDeleted(profile, input.getListName());
}
if (profile.getCurrentSavedBags().containsKey(input.getListName())) {
throw new BadRequestException("Attempt to overwrite an existing bag - name:'" + input.getListName() + "'");
}
GenomicRegionSearchListInput searchInput = (GenomicRegionSearchListInput) input;
InterMineBag tempBag;
try {
tempBag = doListCreation(searchInput, profile, type);
} catch (UnknownBagTypeException e) {
throw new BadRequestException(e.getMessage(), e);
}
addOutputInfo(LIST_SIZE_KEY, tempBag.getSize() + "");
List<String> row = new ArrayList<String>(searchInput.getSearchInfo().getInvalidSpans());
output.addResultItem(row);
if (!input.getTags().isEmpty()) {
im.getBagManager().addTagsToBag(input.getTags(), tempBag, profile);
}
profile.renameBag(input.getTemporaryListName(), input.getListName());
}
use of org.intermine.webservice.server.exceptions.BadRequestException in project intermine by intermine.
the class FastaQueryService method checkPathQuery.
@Override
protected void checkPathQuery(PathQuery pq) throws Exception {
Path path = pq.makePath(pq.getView().get(0));
ClassDescriptor klazz = path.getLastClassDescriptor();
ClassDescriptor sf = im.getModel().getClassDescriptorByName("SequenceFeature");
ClassDescriptor protein = im.getModel().getClassDescriptorByName("Protein");
if (sf == klazz || protein == klazz || klazz.getAllSuperDescriptors().contains(sf) || klazz.getAllSuperDescriptors().contains(protein)) {
// OK
return;
} else {
throw new BadRequestException("Unsuitable type for export: " + klazz);
}
}
use of org.intermine.webservice.server.exceptions.BadRequestException in project intermine by intermine.
the class BGPropertiesCreationService method execute.
@Override
protected void execute() throws Exception {
if (!getPermission().getProfile().isSuperuser()) {
throw new ServiceForbiddenException("Only admins users can access this service");
}
String key = getRequiredParameter("key");
String value = getRequiredParameter("value");
ObjectStoreWriter uosw = im.getProfileManager().getProfileObjectStoreWriter();
String bgPropsAsString = MetadataManager.retrieve(((ObjectStoreInterMineImpl) uosw).getDatabase(), MetadataManager.BG_PROPERTIES);
ObjectMapper mapper = new ObjectMapper();
HashMap<String, String> bgMap;
if (bgPropsAsString == null) {
bgMap = new HashMap<>();
} else {
bgMap = mapper.readValue(bgPropsAsString, HashMap.class);
if (bgMap.containsKey(key)) {
throw new BadRequestException("A property with key " + key + " already exists.");
}
}
bgMap.put(key, value);
MetadataManager.store(((ObjectStoreInterMineImpl) uosw).getDatabase(), MetadataManager.BG_PROPERTIES, mapper.writeValueAsString(bgMap));
}
use of org.intermine.webservice.server.exceptions.BadRequestException in project intermine by intermine.
the class ListUploadService method getReader.
/**
* Get the reader for the identifiers uploaded with this request.
* @param request The request object.
* @return A buffered reader for reading the identifiers.
*/
protected BufferedReader getReader(final HttpServletRequest request) {
BufferedReader r = null;
if (ServletFileUpload.isMultipartContent(request)) {
final ServletFileUpload upload = new ServletFileUpload();
try {
final FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext()) {
final FileItemStream item = iter.next();
final String fieldName = item.getFieldName();
if (!item.isFormField() && "identifiers".equalsIgnoreCase(fieldName)) {
final InputStream stream = item.openStream();
final InputStreamReader in = new InputStreamReader(stream);
r = new BufferedReader(in);
break;
}
}
} catch (FileUploadException e) {
throw new ServiceException("Could not read request body", e);
} catch (IOException e) {
throw new ServiceException(e);
}
} else {
if (!requestIsOfSuitableType()) {
throw new BadRequestException("Bad content type - " + request.getContentType() + USAGE);
}
try {
r = request.getReader();
} catch (IOException e) {
throw new ServiceException(e);
}
}
if (r == null) {
throw new BadRequestException("No identifiers found in request." + USAGE);
}
return r;
}
use of org.intermine.webservice.server.exceptions.BadRequestException in project intermine by intermine.
the class ListOperationService method makeList.
@Override
protected void makeList(ListInput input, String type, Profile profile, Set<String> rubbishbin) throws Exception {
int size = 0;
InterMineBag newBag;
BagOperation operation = getOperation(input);
operation.setClassKeys(im.getClassKeys());
try {
// Make sure we can clean up if ANYTHING goes wrong.
rubbishbin.add(operation.getNewBagName());
} catch (IncompatibleTypes e) {
throw new BadRequestException("Incompatible types", e);
}
try {
if (type == null) {
addOutputInfo(ListMakerService.LIST_TYPE_KEY, operation.getNewBagType());
}
newBag = operation.operate();
size = newBag.getSize();
} catch (NoContent e) {
// This service guarantees a bag, even an empty one.
size = 0;
newBag = profile.createBag(// If this throws, it should have done so by now.
operation.getNewBagName(), // If this throws, it should have done so by now.
operation.getNewBagType(), input.getDescription(), im.getClassKeys());
}
addOutputInfo(LIST_ID_KEY, newBag.getSavedBagId().toString());
if (input.getDescription() != null) {
newBag.setDescription(input.getDescription());
}
if (!input.getTags().isEmpty()) {
bagManager.addTagsToBag(input.getTags(), newBag, profile);
}
output.addResultItem(Arrays.asList("" + size));
if (input.doReplace()) {
ListServiceUtils.ensureBagIsDeleted(profile, input.getListName());
}
profile.renameBag(newBag.getName(), input.getListName());
}
Aggregations