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

ElementView class removed

parent 891cdfe8
No related branches found
No related tags found
1 merge request!286Resolve "Remove View objects from service"
package lcsb.mapviewer.services.search;
import java.io.Serializable;
import java.util.Comparator;
/**
* Abstract view of objects. Contains only identifier of element. Subclasses
* contain additional (partial) information that should be send to the client
* side.
*
* @author Piotr Gawron
*
*/
public abstract class ElementView implements Serializable {
public static final Comparator<? super ElementView> ID_COMPARATOR = new Comparator<ElementView>() {
@Override
public int compare(ElementView o1, ElementView o2) {
return o1.getIdObject().compareTo(o2.getIdObject());
}
};
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Identifier of the {@link lcsb.mapviewer.model.map.model.Model} where Alias is
* located.
*/
private Integer modelId;
/**
* Database identifier of the object that we pass to the bean layer.
*/
private String idObject;
/**
* Default constructor.
*
* @param identifier
* unique identifier of the object ({@link #idObject})
* @param modelId
* identifier of the model ({@link #modelId})
*
*/
protected ElementView(String identifier, Integer modelId) {
this.idObject = identifier;
this.modelId = modelId;
}
/**
* Default constructor.
*
* @param identifier
* unique identifier of the object ({@link #idObject})
* @param modelId
* identifier of the model ({@link #modelId})
*
*/
protected ElementView(Integer identifier, Integer modelId) {
this.idObject = identifier + "";
this.modelId = modelId;
}
/**
* Constructor that should be used only for (de)serialization.
*/
protected ElementView() {
}
/**
* @return the modelId
* @see #modelId
*/
public Integer getModelId() {
return modelId;
}
/**
* @param modelId
* the modelId to set
* @see #modelId
*/
public void setModelId(Integer modelId) {
this.modelId = modelId;
}
/**
* @return the idObject
* @see #idObject
*/
public String getIdObject() {
return idObject;
}
/**
* @param idObject
* the idObject to set
* @see #idObject
*/
public void setIdObject(String idObject) {
this.idObject = idObject;
}
/**
* @param idObject
* the idObject to set
* @see #idObject
*/
public void setIdObject(Integer idObject) {
this.idObject = idObject + "";
}
/**
* @return the uniqueId
* @see #uniqueId
*/
public String getUniqueId() {
return idObject;
}
/**
* @param uniqueId
* the uniqueId to set
* @see #uniqueId
*/
public void setUniqueId(String uniqueId) {
this.idObject = uniqueId;
}
}
package lcsb.mapviewer.services.search;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;
import com.google.gson.Gson;
/**
* Generic factory class for object to be send to the client browser.
*
* @author Piotr Gawron
*
* @param <T>
* heavy data object type used on server side
* @param <S>
* view class representing objects on client side
*/
@Transactional(value = "txManager")
public abstract class ElementViewFactory<T, S> {
/**
* Creates view from object on server side.
*
* @param object
* original object
* @return view object
*/
public abstract S create(T object);
/**
* Get json string for an object.
*
* @param object
* object to be serialized to json
* @return json string for an object
*/
public abstract String createGson(S object);
/**
* Get json string for object list.
*
* @param list
* list of objects to be serialized to json
* @return json string input
*/
public String createGson(List<S> list) {
return new Gson().toJson(list);
}
/**
* Creates list of views from objects on server side.
*
* @param objects
* original objects
* @return list of views
*/
public List<S> createList(Collection<? extends T> objects) {
List<S> result = new ArrayList<S>();
for (T object : objects) {
result.add(create(object));
}
return result;
}
}
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