Skip to content
Snippets Groups Projects
Commit 34441b4d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

LightAliasView class removed

parent bce0fd73
No related branches found
No related tags found
1 merge request!286Resolve "Remove View objects from service"
Showing
with 90 additions and 460 deletions
......@@ -32,8 +32,6 @@ import lcsb.mapviewer.persist.dao.map.ModelDao;
import lcsb.mapviewer.services.interfaces.ILayoutService;
import lcsb.mapviewer.services.interfaces.IModelService;
import lcsb.mapviewer.services.interfaces.IUserService;
import lcsb.mapviewer.services.search.data.LightAliasView;
import lcsb.mapviewer.services.search.data.LightAliasViewFactory;
/**
* Implementation of the service that manages models.
......@@ -298,13 +296,6 @@ public class ModelService implements IModelService {
models.remove(projectId);
}
@Override
public List<LightAliasView> getLightAliasesByIds(Model model, List<Pair<Integer, Integer>> identifiers) {
LightAliasViewFactory lightAliasViewFactory = new LightAliasViewFactory();
List<LightAliasView> result = lightAliasViewFactory.createList(getAliasesByIds(model, identifiers));
return result;
}
/**
* Returns list of {@link Element aliases} for given identifiers.
*
......
package lcsb.mapviewer.services.interfaces;
import java.util.List;
import lcsb.mapviewer.common.IProgressUpdater;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.services.SecurityException;
import lcsb.mapviewer.services.search.data.LightAliasView;
/**
* Service that manages models (maps).
......@@ -72,20 +68,5 @@ public interface IModelService {
*/
void removeModelFromCacheByProjectId(String projectId);
/**
* Returns list of {@link LightAliasView aliases} for given identifiers.
*
* @param model
* model where aliases are located
* @param identifiers
* list of alias identifiers in a given submodel. Every {@link Pair}
* contains information about {@link Model#getId() model identifier}
* (in {@link Pair#left}) and
* {@link lcsb.mapviewer.model.map.species.Element#getId() alias
* identifier} (in {@link Pair#right}).
* @return list of {@link LightAliasView aliases} for given identifiers
*/
List<LightAliasView> getLightAliasesByIds(Model model, List<Pair<Integer, Integer>> identifiers);
void updateModel(ModelData model, String token) throws SecurityException;
}
package lcsb.mapviewer.services.search.data;
import java.awt.geom.Rectangle2D;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.services.search.ElementView;
import lcsb.mapviewer.services.search.ILightView;
/**
* Light {@link ElementView view} for alias representing data that should be
* send to client.
*
* @author Piotr Gawron
*
*/
public class LightAliasView extends ElementView implements ILightView {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Coordinates of the alias.
*/
private Rectangle2D bounds;
/**
* Icon representing this alias on the map.
*/
private String icon;
/**
* Default constructor.
*
* @param alias
* original {@link Element} from which the object is created
* @param icon
* {@link #icon} - icon representing this alias on the map
*/
protected LightAliasView(Element alias, String icon) {
super(alias.getId(), alias.getModel().getId());
if (alias != null) {
this.bounds = new Rectangle2D.Double(alias.getX(), alias.getY(), alias.getWidth(), alias.getHeight());
}
setIcon(icon);
}
/**
* Constructor copying data from the original object.
*
* @param original
* original object from which data will be copied
*/
protected LightAliasView(LightAliasView original) {
super(original.getUniqueId(), original.getModelId());
setBounds(
new Rectangle2D.Double(original.getBounds().getX(), original.getBounds().getY(), original.getBounds().getWidth(), original.getBounds().getHeight()));
setIcon(original.getIcon());
}
/**
* Constructor that should be used only for (de)serialization.
*/
protected LightAliasView() {
super();
}
/**
* @return the bounds
* @see #bounds
*/
public Rectangle2D getBounds() {
return bounds;
}
/**
* @param bounds
* the bounds to set
* @see #bounds
*/
public void setBounds(Rectangle2D bounds) {
this.bounds = bounds;
}
/**
* @return the icon
* @see #icon
*/
public String getIcon() {
return icon;
}
/**
* @param icon
* the icon to set
* @see #icon
*/
public void setIcon(String icon) {
this.icon = icon;
}
}
package lcsb.mapviewer.services.search.data;
import org.apache.log4j.Logger;
import com.google.gson.Gson;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.services.search.ElementViewFactory;
import lcsb.mapviewer.services.search.ILightView;
/**
* Factory class for {@link LightAliasView} class.
*
* @author Piotr Gawron
*
*/
public class LightAliasViewFactory extends ElementViewFactory<Element, LightAliasView> {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(LightAliasViewFactory.class);
@Override
public LightAliasView create(Element alias) {
return create(alias, null);
}
/**
* Creates {@link LightAliasView} for {@link Element}.
*
* @param alias
* alias for which view is created
* @param icon
* icon that should be assigned to the view
* @return {@link LightAliasView} for {@link Element}
*/
public LightAliasView create(Element alias, String icon) {
LightAliasView result = new LightAliasView(alias, icon);
return result;
}
@Override
public String createGson(LightAliasView object) {
return new Gson().toJson(object);
}
/**
* Creates {@link ILightView} from {@link FullAliasView}.
*
* @param object
* original object
* @return new light object
*/
public ILightView create(LightAliasView object) {
return new LightAliasView(object);
}
}
......@@ -9,7 +9,6 @@ import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.model.map.layout.GeneVariation;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.services.search.IHeavyView;
import lcsb.mapviewer.services.search.data.LightAliasView;
import lcsb.mapviewer.services.utils.data.ColorSchemaType;
/**
......@@ -21,95 +20,95 @@ import lcsb.mapviewer.services.utils.data.ColorSchemaType;
*/
public class FullLayoutAliasView extends LightLayoutAliasView implements IHeavyView {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(FullLayoutAliasView.class);
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Description.
*
* @see ColorSchema#description
*/
private String description;
/**
* Type of the layout.
*
* @see ColorSchema#getClass()
*/
private ColorSchemaType type;
/**
* List of gene variants.
*/
private List<GeneVariation> geneVariations = new ArrayList<>();
/**
* Default constructor.
*
* @param alias
* object for which vie is created
*/
protected FullLayoutAliasView(Element alias) {
super(alias);
}
/**
* @return the description
* @see #description
*/
public String getDescription() {
return description;
}
/**
* @param description
* the description to set
* @see #description
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @return the type
* @see #type
*/
public ColorSchemaType getType() {
return type;
}
/**
* @param type
* the type to set
* @see #type
*/
public void setType(ColorSchemaType type) {
this.type = type;
}
/**
* @return the geneVariations
* @see #geneVariations
*/
public List<GeneVariation> getGeneVariations() {
return geneVariations;
}
/**
* @param geneVariations
* the geneVariations to set
* @see #geneVariations
*/
public void setGeneVariations(List<GeneVariation> geneVariations) {
this.geneVariations = geneVariations;
}
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(FullLayoutAliasView.class);
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Description.
*
* @see ColorSchema#description
*/
private String description;
/**
* Type of the layout.
*
* @see ColorSchema#getClass()
*/
private ColorSchemaType type;
/**
* List of gene variants.
*/
private List<GeneVariation> geneVariations = new ArrayList<>();
/**
* Default constructor.
*
* @param alias
* object for which vie is created
*/
protected FullLayoutAliasView(Element alias) {
super(alias);
}
/**
* @return the description
* @see #description
*/
public String getDescription() {
return description;
}
/**
* @param description
* the description to set
* @see #description
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @return the type
* @see #type
*/
public ColorSchemaType getType() {
return type;
}
/**
* @param type
* the type to set
* @see #type
*/
public void setType(ColorSchemaType type) {
this.type = type;
}
/**
* @return the geneVariations
* @see #geneVariations
*/
public List<GeneVariation> getGeneVariations() {
return geneVariations;
}
/**
* @param geneVariations
* the geneVariations to set
* @see #geneVariations
*/
public void setGeneVariations(List<GeneVariation> geneVariations) {
this.geneVariations = geneVariations;
}
}
......@@ -44,7 +44,4 @@
<!-- Encoder used for hashing passwords -->
<bean id="PasswordEncoder" class="lcsb.mapviewer.services.impl.Md5PasswordEncoder"/>
<!-- View factories -->
<bean id="LightAliasViewFactory" class="lcsb.mapviewer.services.search.data.LightAliasViewFactory"/>
</beans>
\ No newline at end of file
......@@ -10,7 +10,6 @@ import org.junit.runners.Suite.SuiteClasses;
ExternalServicesServiceTest.class, //
LayoutServiceTest.class, //
Md5PasswordEncoderTest.class, //
ModelServiceTest.class, //
ProjectServiceTest.class, //
SearchServiceTest.class, //
UserServiceTest.class,//
......
package lcsb.mapviewer.services.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import lcsb.mapviewer.annotation.services.PubmedParser;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.services.ServiceTestFunctions;
import lcsb.mapviewer.services.interfaces.IModelService;
import lcsb.mapviewer.services.search.data.LightAliasView;
@Rollback(true)
public class ModelServiceTest extends ServiceTestFunctions {
static Logger logger = Logger.getLogger(ModelServiceTest.class);
@Autowired
IModelService modelService;
@Autowired
PubmedParser backend;
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testGetAliasByIds() throws Exception {
try {
Model model = getModelForFile("testFiles/sample.xml", false);
int counter = 0;
Element alias0 = null;
for (Element alias : model.getElements()) {
if (counter == 0) {
alias0 = alias;
}
alias.setId(counter++);
}
List<Pair<Integer, Integer>> identifiers = new ArrayList<>();
identifiers.add(new Pair<Integer, Integer>(0, 0));
List<LightAliasView> list = modelService.getLightAliasesByIds(model, identifiers);
assertEquals(1, list.size());
assertEquals(alias0.getX(), list.get(0).getBounds().getX(), EPSILON);
assertEquals(alias0.getY(), list.get(0).getBounds().getY(), EPSILON);
assertEquals(alias0.getWidth(), list.get(0).getBounds().getWidth(), EPSILON);
assertEquals(alias0.getHeight(), list.get(0).getBounds().getHeight(), EPSILON);
identifiers.add(new Pair<Integer, Integer>(0, 5));
list = modelService.getLightAliasesByIds(model, identifiers);
assertEquals(2, list.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetAliasByInvalidIds() throws Exception {
try {
Model model = getModelForFile("testFiles/db_problem_model.xml", false);
List<Pair<Integer, Integer>> identifiers = new ArrayList<>();
// check with wrong alias id
identifiers.add(new Pair<Integer, Integer>(0, 1));
try {
modelService.getLightAliasesByIds(model, identifiers);
fail(InvalidArgumentException.class + " expected");
} catch (InvalidArgumentException e) {
}
identifiers = new ArrayList<>();
// check with wrong model id
identifiers.add(new Pair<Integer, Integer>(1, 0));
try {
modelService.getLightAliasesByIds(model, identifiers);
fail(InvalidArgumentException.class + " expected");
} catch (InvalidArgumentException e) {
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
......@@ -4,13 +4,11 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import lcsb.mapviewer.services.search.data.AllSearchDataTests;
import lcsb.mapviewer.services.search.db.AllSearchDbTests;
import lcsb.mapviewer.services.search.layout.AllSearchLayoutTests;
@RunWith(Suite.class)
@SuiteClasses({ AllSearchDbTests.class, //
AllSearchDataTests.class, //
AllSearchLayoutTests.class, //
ElementMatcherTest.class, //
})
......
package lcsb.mapviewer.services.search.data;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ LightAliasViewFactoryTest.class,})
public class AllSearchDataTests {
}
package lcsb.mapviewer.services.search.data;
import static org.junit.Assert.assertNotNull;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.GenericProtein;
public class LightAliasViewFactoryTest {
Logger logger = Logger.getLogger(LightAliasViewFactoryTest.class);
LightAliasViewFactory lightAliasViewFactory = new LightAliasViewFactory();
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testCreateGson() throws Exception {
try {
Element alias = new GenericProtein("id");
alias.setModel(new ModelFullIndexed(null));
LightAliasView object = lightAliasViewFactory.create(alias);
String gson = lightAliasViewFactory.createGson(object);
assertNotNull(gson);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
package lcsb.mapviewer.services.search.data;
import org.junit.After;
import org.junit.Before;
public class LightAliasViewTest {
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment