Search in sources :

Example 1 with BadRequestException

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());
}
Also used : ArrayList(java.util.ArrayList) BadRequestException(org.intermine.webservice.server.exceptions.BadRequestException) UnknownBagTypeException(org.intermine.api.bag.UnknownBagTypeException) InterMineBag(org.intermine.api.profile.InterMineBag)

Example 2 with BadRequestException

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);
    }
}
Also used : Path(org.intermine.pathquery.Path) ClassDescriptor(org.intermine.metadata.ClassDescriptor) BadRequestException(org.intermine.webservice.server.exceptions.BadRequestException)

Example 3 with BadRequestException

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));
}
Also used : HashMap(java.util.HashMap) BadRequestException(org.intermine.webservice.server.exceptions.BadRequestException) ServiceForbiddenException(org.intermine.webservice.server.exceptions.ServiceForbiddenException) ObjectStoreWriter(org.intermine.objectstore.ObjectStoreWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with BadRequestException

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;
}
Also used : ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) InputStreamReader(java.io.InputStreamReader) ServiceException(org.intermine.webservice.server.exceptions.ServiceException) FileItemStream(org.apache.commons.fileupload.FileItemStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) BadRequestException(org.intermine.webservice.server.exceptions.BadRequestException) IOException(java.io.IOException) FileItemIterator(org.apache.commons.fileupload.FileItemIterator) FileUploadException(org.apache.commons.fileupload.FileUploadException)

Example 5 with BadRequestException

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());
}
Also used : BagOperation(org.intermine.api.bag.operations.BagOperation) NoContent(org.intermine.api.bag.operations.NoContent) BadRequestException(org.intermine.webservice.server.exceptions.BadRequestException) InterMineBag(org.intermine.api.profile.InterMineBag) IncompatibleTypes(org.intermine.api.bag.operations.IncompatibleTypes)

Aggregations

BadRequestException (org.intermine.webservice.server.exceptions.BadRequestException)55 Profile (org.intermine.api.profile.Profile)23 ServiceException (org.intermine.webservice.server.exceptions.ServiceException)14 InterMineBag (org.intermine.api.profile.InterMineBag)13 HashMap (java.util.HashMap)12 PathQuery (org.intermine.pathquery.PathQuery)10 Path (org.intermine.pathquery.Path)9 ArrayList (java.util.ArrayList)8 ObjectStoreException (org.intermine.objectstore.ObjectStoreException)7 PathException (org.intermine.pathquery.PathException)7 ResourceNotFoundException (org.intermine.webservice.server.exceptions.ResourceNotFoundException)7 ServiceForbiddenException (org.intermine.webservice.server.exceptions.ServiceForbiddenException)7 TemplateQuery (org.intermine.template.TemplateQuery)6 StringReader (java.io.StringReader)5 HashSet (java.util.HashSet)5 ApiTemplate (org.intermine.api.template.ApiTemplate)4 ClassDescriptor (org.intermine.metadata.ClassDescriptor)4 Query (org.intermine.objectstore.query.Query)4 IOException (java.io.IOException)3 Reader (java.io.Reader)3