/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ucp.ws;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import ucp.model.UcpMetrics;
import ucp.model.UcpModel;
import ucp.plan.UcpComputing;

/**
 * Web service provides operations to count UCP model
 * 
 * @author Trifolium Alpestre
 */
@WebService()
public class UseCasePlan {
    
        
    /**
     * Web service operation used to count UCP model
     * 
     * @param metrics
     * @param xmlModel
     * @return 
     */
    @WebMethod(operationName = "countUCP")
    public ArrayList<UcpElement> countUCP(@WebParam(name = "metrics")
    UcpWsMetrics metrics, @WebParam(name = "xmlModel")
    String xmlModel){
       
        
        UcpModel model;
        ArrayList<UcpElement> eList = null;
        UcpComputing ucpComputing = new UcpComputing();
        Model2Elements m2e = new Model2Elements();
        UcpMetrics ucpMetrics = new UcpMetrics();


        //zkopirovani atributu z UcpWsMetrics do UcpMetrics
        ucpMetrics.setTx(0, metrics.getT1());
        ucpMetrics.setTx(1, metrics.getT2());
        ucpMetrics.setTx(2, metrics.getT3());
        ucpMetrics.setTx(3, metrics.getT4());
        ucpMetrics.setTx(4, metrics.getT5());
        ucpMetrics.setTx(5, metrics.getT6());
        ucpMetrics.setTx(6, metrics.getT7());
        ucpMetrics.setTx(7, metrics.getT8());
        ucpMetrics.setTx(8, metrics.getT9());
        ucpMetrics.setTx(9, metrics.getT10());
        ucpMetrics.setTx(10, metrics.getT11());
        ucpMetrics.setTx(11, metrics.getT12());
        ucpMetrics.setTx(12, metrics.getT13());
        ucpMetrics.setEx(0, metrics.getE1());
        ucpMetrics.setEx(1, metrics.getE2());
        ucpMetrics.setEx(2, metrics.getE3());
        ucpMetrics.setEx(3, metrics.getE4());
        ucpMetrics.setEx(4, metrics.getE5());
        ucpMetrics.setEx(5, metrics.getE6());
        ucpMetrics.setEx(6, metrics.getE7());
        ucpMetrics.setEx(7, metrics.getE8());
        ucpMetrics.setHoursPerUc(metrics.getHoursPerUc());

        try {                  
            //vytvoreni, vypocitani a vraceni modelu
            model = ucpComputing.createUcpModel(xmlModel); //z xml stringu udelat ucp model
            ucpComputing.setMetrics(ucpMetrics, model); //jednoduche nastaveni metrics vsem elementum modelu
            ucpComputing.countUcp(model, 2); //vypocet ucp u modelu, nastaven level vypoctu
            eList = m2e.transform(model); //z ucp modelu udelat kolekci elementu pro WS
            return eList;
        
        } catch (Exception ex) {
            Logger.getLogger(UseCasePlan.class.getName()).log(Level.SEVERE, null, ex);
            
            return eList;//vrati se prazdny seznam elementu  
        }
    }

}
