Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove static presets. #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.ac.ebi.quickgo.client.model.presets;

import com.fasterxml.jackson.annotation.JsonFilter;

import java.util.List;

/**
Expand All @@ -28,10 +27,6 @@ public interface CompositePreset {

List<PresetItem> getQualifiers();

List<PresetItem> getAspects();

List<PresetItem> getGeneProductTypes();

List<PresetItem> getExtRelations();

List<PresetItem> getExtDatabases();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public CompositePresetImpl() {
for (PresetType presetType : PresetType.values()) {
presetsMap.put(presetType, new LinkedHashSet<>());
}

initialiseStaticPresets();
}

public void addPreset(PresetType presetType, PresetItem presetItem) {
Expand Down Expand Up @@ -104,14 +102,6 @@ public void addPreset(PresetType presetType, PresetItem presetItem) {
return sortedPresetItems(QUALIFIERS);
}

@Override public List<PresetItem> getAspects() {
return sortedPresetItems(ASPECTS);
}

@Override public List<PresetItem> getGeneProductTypes() {
return sortedPresetItems(GENE_PRODUCT_TYPES);
}

@Override
public List<PresetItem> getExtRelations() {
return sortedPresetItems(EXT_RELATIONS);
Expand All @@ -122,11 +112,6 @@ public List<PresetItem> getExtDatabases() {
return sortedPresetItems(EXT_DATABASES);
}

private void initialiseStaticPresets() {
presetsMap.put(ASPECTS, StaticAspects.createAspects());
presetsMap.put(GENE_PRODUCT_TYPES, StaticGeneProductTypes.createGeneProductTypes());
}

/**
* Sorts the presets according to the ordering rules defined in the class description. This method
* makes use of the default grouping function defined by {@link CompositePresetImpl#defaultGrouping()}.
Expand Down Expand Up @@ -230,50 +215,4 @@ private static void ifPresetItemMatchesThenApply(
.findFirst()
.ifPresent(itemConsumer);
}

private static class StaticAspects {

static Set<PresetItem> createAspects() {
Set<PresetItem> presetAspects = new HashSet<>();
Arrays.stream(Aspect.values())
.forEach(aspect -> insertAspect(presetAspects, aspect));
return presetAspects;
}

private static void insertAspect(Set<PresetItem> presets, Aspect aspect) {
presets.add(PresetItem
.createWithName(aspect.getFullName())
.withProperty(PresetItem.Property.ID.getKey(), aspect.getScientificName()).build());
}
}

private static class StaticGeneProductTypes {

private enum GeneProductType {
PROTEINS("Proteins", "protein"),
RNA("RNA", "miRNA"),
COMPLEXES("Complexes", "complex");

private final String name;
private final String shortName;

GeneProductType(String name, String shortName) {
this.name = name;
this.shortName = shortName;
}
}

static Set<PresetItem> createGeneProductTypes() {
Set<PresetItem> presetAspects = new HashSet<>();
Arrays.stream(GeneProductType.values())
.forEach(aspect -> insertGeneProductType(presetAspects, aspect));
return presetAspects;
}

private static void insertGeneProductType(Set<PresetItem> presets, GeneProductType geneProductType) {
presets.add(PresetItem
.createWithName(geneProductType.name)
.withProperty(PresetItem.Property.ID.getKey(), geneProductType.shortName).build());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package uk.ac.ebi.quickgo.client.controller;

import uk.ac.ebi.quickgo.client.QuickGOREST;
import uk.ac.ebi.quickgo.client.model.presets.impl.CompositePresetImpl;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -10,8 +13,6 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import uk.ac.ebi.quickgo.client.QuickGOREST;
import uk.ac.ebi.quickgo.client.model.presets.impl.CompositePresetImpl;

import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
Expand Down Expand Up @@ -106,22 +107,6 @@ public void canRetrieveQualifierPresets() throws Exception {
.andExpect(jsonPath("$.qualifiers").exists());
}

@Test
public void canRetrieveAspectPresets() throws Exception {
mockMvc.perform(get(RESOURCE_URL))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.aspects.*", hasSize(3)));
}

@Test
public void canRetrieveGeneProductTypesPresets() throws Exception {
mockMvc.perform(get(RESOURCE_URL))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.geneProductTypes.*", hasSize(3)));
}

@Test
public void canRetrieveAnnotationExtensionRelationsPresets() throws Exception {
mockMvc.perform(get(RESOURCE_URL))
Expand Down