/**
 * 
 */
package gov.nih.nci.calab.dto.function;

import gov.nih.nci.calab.domain.nano.function.Function;
import gov.nih.nci.calab.domain.nano.function.Linkage;
import gov.nih.nci.calab.service.util.CananoConstants;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zengje
 *
 */
public class FunctionBean {

	private String id;
	private String type;
	private String activationMethod;
	private String description;
	private String viewTitle;
	
	private List<LinkageBean> linkages = new ArrayList<LinkageBean>();;
	private int numberOfLinkages;
	
	/**
	 * 
	 */
	public FunctionBean() {
		super();
		// TODO Auto-generated constructor stub
	}

	public FunctionBean(String id, String type, String viewTitle) {
		this.id=id;		
		this.type=type;
		this.viewTitle=viewTitle;
	}
	
	public FunctionBean(Function function) {
		this.id=function.getId().toString();
		this.type=function.getType();
		this.activationMethod=function.getActivationMethod();
		this.description=function.getDescription();
		this.viewTitle=function.getIdentificationName();
		for(Linkage linkage: function.getLinkageCollection()) {
			linkages.add(new LinkageBean(linkage));
		}
		this.numberOfLinkages=linkages.size();
	}
	
	public String getActivationMethod() {
		return activationMethod;
	}

	public void setActivationMethod(String activationMethod) {
		this.activationMethod = activationMethod;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public List<LinkageBean> getLinkages() {
		return linkages;
	}

	public void setLinkages(List<LinkageBean> linkages) {
		this.linkages = linkages;
	}

	public int getNumberOfLinkages() {
		return numberOfLinkages;
	}

	public void setNumberOfLinkages(int numberOfLinkages) {
		this.numberOfLinkages = numberOfLinkages;
	}

	public String getViewTitle() {
			// get only the first number of characters of the title
		if (viewTitle!=null &&viewTitle.length() > CananoConstants.MAX_VIEW_TITLE_LENGTH) {
			return viewTitle.substring(0, CananoConstants.MAX_VIEW_TITLE_LENGTH);
		}
		return viewTitle;
	}

	public void setViewTitle(String viewTitle) {
		this.viewTitle = viewTitle;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Function getDomainObj(){
		Function doFunction = new Function();
		if (getId() != null && getId().length() > 0) {
			doFunction.setId(new Long(getId()));
		}
		doFunction.setActivationMethod(activationMethod);
		doFunction.setDescription(description);
		doFunction.setIdentificationName(viewTitle);
		doFunction.setType(type);
		for (LinkageBean linkage: getLinkages()) {
			doFunction.getLinkageCollection().add(linkage.getDomainObj());
		}
		return doFunction;
	}
}

@@ -535,19 +535,22 @@
 private 
+Str
 in
-t
+g
  numberO
@@ -1201,16 +1201,19 @@
 s.size()
++%22%22
 ;%0A%09%7D%0A%09%0A%09
@@ -1791,19 +1791,22 @@
 %09public 
+Str
 in
-t
+g
  getNumb
@@ -1890,11 +1890,14 @@
 ges(
+Str
 in
-t
+g
  num

update numberOfLinkages to be a String