Search in sources :

Example 1 with WellComposedErrorBody

use of ubic.gemma.web.services.rest.util.WellComposedErrorBody in project Gemma by PavlidisLab.

the class FilterArg method getObjectFilters.

/**
 * Creates an ArrayList of Object Filter arrays, that can be used as a filter parameter for service value object
 * retrieval.
 *
 * @return an ArrayList of Object Filter arrays, each array represents a disjunction (OR) of filters. Arrays
 * then represent a conjunction (AND) with other arrays in the list.
 */
public ArrayList<ObjectFilter[]> getObjectFilters() {
    this.checkMalformed();
    if (propertyNames == null || propertyNames.isEmpty())
        return null;
    ArrayList<ObjectFilter[]> filterList = new ArrayList<>(propertyNames.size());
    for (int i = 0; i < propertyNames.size(); i++) {
        try {
            String[] properties = propertyNames.get(i);
            String[] values = propertyValues.get(i);
            String[] operators = propertyOperators.get(i);
            Class[] types = propertyTypes.get(i);
            ObjectFilter[] filterArray = new ObjectFilter[properties.length];
            for (int j = 0; j < properties.length; j++) {
                filterArray[j] = new ObjectFilter(properties[j], types[j], values[j], operators[j], objectAlias);
            }
            filterList.add(filterArray);
        } catch (IndexOutOfBoundsException e) {
            throw new GemmaApiException(new WellComposedErrorBody(Response.Status.BAD_REQUEST, ERROR_MSG_ARGS_MISALIGNED));
        } catch (ParseException e) {
            WellComposedErrorBody error = new WellComposedErrorBody(Response.Status.BAD_REQUEST, ERROR_MSG_MALFORMED_REQUEST);
            WellComposedErrorBody.addExceptionFields(error, e);
            throw new GemmaApiException(error);
        }
    }
    return filterList;
}
Also used : ArrayList(java.util.ArrayList) WellComposedErrorBody(ubic.gemma.web.services.rest.util.WellComposedErrorBody) ObjectFilter(ubic.gemma.persistence.util.ObjectFilter) GemmaApiException(ubic.gemma.web.services.rest.util.GemmaApiException) ParseException(java.text.ParseException)

Example 2 with WellComposedErrorBody

use of ubic.gemma.web.services.rest.util.WellComposedErrorBody in project Gemma by PavlidisLab.

the class TaxonArg method getGenesOnChromosome.

/**
 * Lists Genes overlapping a location on a specific chromosome on a taxon that this TaxonArg represents.
 *
 * @param taxonService      the service that will be used to retrieve the persistent Taxon object.
 * @param chromosomeService the service that will be used to find the Chromosome object.
 * @param geneService       the service that will be used to retrieve the Gene VOs
 * @param chromosomeName    name of the chromosome to look on
 * @param start             the start nucleotide denoting the location to look for genes at.
 * @param size              the size (in nucleotides) of the location from the 'start' nucleotide.
 * @return collection of Gene VOs overlapping the location defined by the 'start' and 'size' parameters.
 */
public Collection<GeneValueObject> getGenesOnChromosome(TaxonService taxonService, ChromosomeService chromosomeService, GeneService geneService, String chromosomeName, long start, int size) {
    // Taxon argument
    Taxon taxon = this.getPersistentObject(taxonService);
    // Chromosome argument
    Collection<Chromosome> chromosomes = chromosomeService.find(chromosomeName, taxon);
    if (chromosomes.isEmpty()) {
        WellComposedErrorBody errorBody = new WellComposedErrorBody(Response.Status.NOT_FOUND, "Chromosome " + chromosomeName + " not found for taxon " + taxon.getScientificName());
        throw new GemmaApiException(errorBody);
    }
    Chromosome chromosome = chromosomes.iterator().next();
    // Setup chromosome location
    PhysicalLocation region = PhysicalLocation.Factory.newInstance(chromosome);
    region.setNucleotide(start);
    region.setNucleotideLength(size);
    // region.setStrand( strand );
    Collection<GeneValueObject> GVOs = geneService.loadValueObjects(geneService.find(region));
    if (GVOs == null) {
        WellComposedErrorBody errorBody = new WellComposedErrorBody(Response.Status.NOT_FOUND, "No genes found on chromosome " + chromosomeName + " between positions " + start + " and " + start + size + ".");
        throw new GemmaApiException(errorBody);
    }
    return GVOs;
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) Taxon(ubic.gemma.model.genome.Taxon) Chromosome(ubic.gemma.model.genome.Chromosome) WellComposedErrorBody(ubic.gemma.web.services.rest.util.WellComposedErrorBody) GemmaApiException(ubic.gemma.web.services.rest.util.GemmaApiException) PhysicalLocation(ubic.gemma.model.genome.PhysicalLocation)

Example 3 with WellComposedErrorBody

use of ubic.gemma.web.services.rest.util.WellComposedErrorBody in project Gemma by PavlidisLab.

the class MutableArg method throwNotFound.

/**
 * Throws a GemmaApiException informing that the object this argument represents was not found.
 */
void throwNotFound() {
    WellComposedErrorBody errorBody = new WellComposedErrorBody(Response.Status.NOT_FOUND, ERROR_MSG_ENTITY_NOT_FOUND);
    WellComposedErrorBody.addExceptionFields(errorBody, new EntityNotFoundException(this.nullCause));
    throw new GemmaApiException(errorBody);
}
Also used : WellComposedErrorBody(ubic.gemma.web.services.rest.util.WellComposedErrorBody) EntityNotFoundException(ubic.gemma.web.util.EntityNotFoundException) GemmaApiException(ubic.gemma.web.services.rest.util.GemmaApiException)

Example 4 with WellComposedErrorBody

use of ubic.gemma.web.services.rest.util.WellComposedErrorBody in project Gemma by PavlidisLab.

the class ArrayEntityArg method convertParseException.

/**
 * Converts the given parse exception into a GemmaApiException with a well composed error body.
 *
 * @param e the exception to be converted.
 * @return a properly populated GemmaApiException describing the given exception.
 */
GemmaApiException convertParseException(ParseException e) {
    WellComposedErrorBody error = new WellComposedErrorBody(Response.Status.BAD_REQUEST, FilterArg.ERROR_MSG_MALFORMED_REQUEST);
    WellComposedErrorBody.addExceptionFields(error, e);
    return new GemmaApiException(error);
}
Also used : WellComposedErrorBody(ubic.gemma.web.services.rest.util.WellComposedErrorBody) GemmaApiException(ubic.gemma.web.services.rest.util.GemmaApiException)

Example 5 with WellComposedErrorBody

use of ubic.gemma.web.services.rest.util.WellComposedErrorBody in project Gemma by PavlidisLab.

the class MalformableArg method checkMalformed.

/**
 * Checks whether the instance of this object was created as a malformed argument, and if true, throws an
 * exception using the information provided in the constructor.
 */
void checkMalformed() {
    if (this.malformed) {
        WellComposedErrorBody body = new WellComposedErrorBody(Response.Status.BAD_REQUEST, errorMessage);
        WellComposedErrorBody.addExceptionFields(body, this.exception);
        throw new GemmaApiException(body);
    }
}
Also used : WellComposedErrorBody(ubic.gemma.web.services.rest.util.WellComposedErrorBody) GemmaApiException(ubic.gemma.web.services.rest.util.GemmaApiException)

Aggregations

GemmaApiException (ubic.gemma.web.services.rest.util.GemmaApiException)5 WellComposedErrorBody (ubic.gemma.web.services.rest.util.WellComposedErrorBody)5 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Chromosome (ubic.gemma.model.genome.Chromosome)1 PhysicalLocation (ubic.gemma.model.genome.PhysicalLocation)1 Taxon (ubic.gemma.model.genome.Taxon)1 GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)1 ObjectFilter (ubic.gemma.persistence.util.ObjectFilter)1 EntityNotFoundException (ubic.gemma.web.util.EntityNotFoundException)1