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

unused PubmedAnnotatedElementsViewFactory removed

parent fb59e45f
No related branches found
No related tags found
1 merge request!207Resolve "remove unused JSF code"
package lcsb.mapviewer.services.view;
import java.util.ArrayList;
import java.util.List;
import lcsb.mapviewer.annotation.data.Article;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.services.impl.SearchService;
/**
* View object for pubmed article for a given model. It contains information
* about article and list of elements annotated by this
* {@link lcsb.mapviewer.model.map.MiriamType#PUBMED article}.
*
* @author Piotr Gawron
*
*/
public class PubmedAnnotatedElementsView extends AbstractView<MiriamData> {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Article for which this pubmed summary is created.
*/
private Article article;
/**
* List of elements that are annotated the publication. {@link Pair#left}
* refers to human readable name and {@link Pair#right} is search string that
* can be used to access element on the model.
*/
private List<Pair<String, String>> elements = new ArrayList<>();
/**
* Default constructor.
*
* @param element
* {@link MiriamData} that represents publication for this object.
*
* @see #article
*/
public PubmedAnnotatedElementsView(MiriamData element) {
super(element);
}
/**
* @return the article
* @see #article
*/
public Article getArticle() {
return article;
}
/**
* @param article
* the article to set
* @see #article
*/
public void setArticle(Article article) {
this.article = article;
}
/**
* @return the elements
* @see #elements
*/
public List<Pair<String, String>> getElements() {
return elements;
}
/**
* @param elements
* the elements to set
* @see #elements
*/
public void setElements(List<Pair<String, String>> elements) {
this.elements = elements;
}
/**
* Adds element annotratd by {@link #article}.
*
* @param annotatedObject
* object to add
*/
public void addElement(BioEntity annotatedObject) {
if (annotatedObject instanceof Element) {
Element alias = (Element) annotatedObject;
elements.add(new Pair<String, String>(alias.getName(), SearchService.SPECIES_SEARCH_PREFIX + ":" + alias.getElementId()));
} else if (annotatedObject instanceof Reaction) {
Reaction reaction = (Reaction) annotatedObject;
elements.add(
new Pair<>(
SearchService.REACTION_SEARCH_PREFIX + ":" + reaction.getIdReaction(), SearchService.REACTION_SEARCH_PREFIX + ":" + reaction.getIdReaction()));
} else {
throw new InvalidStateException("Unknown subtype of " + BioEntity.class.getName() + ": " + annotatedObject.getClass().getName());
}
}
}
package lcsb.mapviewer.services.view;
import java.util.Set;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import com.google.gson.Gson;
import lcsb.mapviewer.annotation.data.Article;
import lcsb.mapviewer.annotation.services.PubmedParser;
import lcsb.mapviewer.annotation.services.PubmedSearchException;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.model.Model;
/**
* Factory class for {@link LayoutView} class.
*
* @author Piotr Gawron
*
*/
public class PubmedAnnotatedElementsViewFactory extends AbstractViewFactory<MiriamData, PubmedAnnotatedElementsView> {
/**
* Default class logger.
*/
private static Logger logger = Logger.getLogger(PubmedAnnotatedElementsViewFactory.class);
/**
* Local backend to the pubmed data.
*/
@Autowired
private PubmedParser pubmedParser;
@Override
public PubmedAnnotatedElementsView create(MiriamData element) {
PubmedAnnotatedElementsView result = new PubmedAnnotatedElementsView(element);
if (element == null) {
return result;
} else if (!MiriamType.PUBMED.equals(element.getDataType())) {
throw new InvalidArgumentException("Only " + MiriamType.PUBMED + " types are valid");
}
try {
result.setArticle(pubmedParser.getPubmedArticleById(Integer.valueOf(element.getResource())));
} catch (PubmedSearchException e) {
Article article = new Article();
article.setTitle("N/A");
result.setArticle(article);
logger.error(e, e);
}
return result;
}
/**
* Creates publication summary for a given model.
*
* @param miriamData
* {@link MiriamData} representing article
* @param model
* model for which summary will be prepared
* @return publication summary for a given model and publication
*/
public PubmedAnnotatedElementsView create(MiriamData miriamData, Model model) {
PubmedAnnotatedElementsView result = create(miriamData);
Set<BioEntity> elements = model.getElementsByAnnotation(miriamData);
for (Model submodel : model.getSubmodels()) {
elements.addAll(submodel.getElementsByAnnotation(miriamData));
}
for (BioEntity annotatedObject : elements) {
result.addElement(annotatedObject);
}
return result;
}
@Override
public String createGson(PubmedAnnotatedElementsView object) {
return new Gson().toJson(object);
}
@Override
public MiriamData viewToObject(PubmedAnnotatedElementsView view) {
throw new NotImplementedException();
}
}
......@@ -57,7 +57,6 @@
<bean id="OverviewLinkViewFactory" class="lcsb.mapviewer.services.view.OverviewLinkViewFactory"/>
<bean id="PrivilegeViewFactory" class="lcsb.mapviewer.services.view.PrivilegeViewFactory"/>
<bean id="ProjectViewFactory" class="lcsb.mapviewer.services.view.ProjectViewFactory"/>
<bean id="PubmedAnnotatedElementsViewFactory" class="lcsb.mapviewer.services.view.PubmedAnnotatedElementsViewFactory"/>
<bean id="ReferenceGenomeViewFactory" class="lcsb.mapviewer.services.view.ReferenceGenomeViewFactory"/>
<bean id="ReferenceGenomeGeneMappingViewFactory" class="lcsb.mapviewer.services.view.ReferenceGenomeGeneMappingViewFactory"/>
......
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