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

package ucp.ws;

import ucp.model.*;
import java.util.ArrayList;

/**
 * Class provides methods to convert UCP model to list of simple UCP elements.
 * 
 * @author Trifolium Alpestre
 */
public class Model2Elements {
    
    private ArrayList<UcpElement> eList = new ArrayList<UcpElement>();//kolekce elementu
    
    
    
    /**
     * 
     * Method converts UCP model to list of simple UCP elements.
     * 
     * @param model
     * @return
     */
    public ArrayList<UcpElement> transform(UcpModel model){
    

            UcpElement em = new UcpElement();//novy ucp element

            em.setIdParent("root");//nastaveni ID rodicovskeho baliku
            em.setId("model");//nastaveni ID baliku
            em.setName("Model");//nastaveni jmena baliku
            em.setType("uml:Package");//nastaveni typu elementu = balik

            em.setComplexity(model.getMetrics().getComplexity());//nastaveni complexity
            em.setHours(model.getMetrics().getHours());//nastaveni celkovych hodin
            em.setHoursPerUc(model.getMetrics().getHoursPerUc());//nastaveni hodin na ucp
            em.setHoursSW(model.getMetrics().getHoursSW());//nastaveni celkovych hodin podle Schneider Winters
            em.setSchneiderwinters(model.getMetrics().getSchneiderwinters());//cas podle Schneider Winters na jeden ucp
            em.setSubCasesHours(model.getMetrics().getSubCasesHours());//celkovy cas sub UseCases
            em.setSubCasesHoursSW(model.getMetrics().getSubCasesHoursSW());//celkovy cas sub UseCases podle Schneider Winters
            em.setUcp(model.getMetrics().getUcp());//nastaveni ucp
            em.setSubUCP(model.getMetrics().getSubUCP());//nastaveni sub ucp
            em.setSubUUCP(model.getMetrics().getSubUUCP());//nastaveni celkove complexity pro sub UseCases

            eList.add(em);//vlozeni vytvoreneho elementu do kolekce



         String parentID = "model";//ID rodicovskeho baliku = model

        //pro kazdy balik z kolekce rodicovskeho baliku
        for (UcpPackage p:model.getPList())
        {
            UcpElement e = new UcpElement();//novy ucp element
            
            e.setIdParent(parentID);//nastaveni ID rodicovskeho baliku
            e.setId(p.getId());//nastaveni ID baliku
            e.setName(p.getName());//nastaveni jmena baliku
            e.setType("uml:Package");//nastaveni typu elementu = balik
            
            e.setComplexity(p.getMetrics().getComplexity());//nastaveni complexity
            e.setHours(p.getMetrics().getHours());//nastaveni celkovych hodin
            e.setHoursPerUc(p.getMetrics().getHoursPerUc());//nastaveni hodin na ucp
            e.setHoursSW(p.getMetrics().getHoursSW());//nastaveni celkovych hodin podle Schneider Winters
            e.setSchneiderwinters(p.getMetrics().getSchneiderwinters());//cas podle Schneider Winters na jeden ucp
            e.setSubCasesHours(p.getMetrics().getSubCasesHours());//celkovy cas sub UseCases
            e.setSubCasesHoursSW(p.getMetrics().getSubCasesHoursSW());//celkovy cas sub UseCases podle Schneider Winters
            e.setUcp(p.getMetrics().getUcp());//nastaveni ucp
            e.setSubUCP(p.getMetrics().getSubUCP());//nastaveni sub ucp
            e.setSubUUCP(p.getMetrics().getSubUUCP());//nastaveni celkove complexity pro sub UseCases
            
            eList.add(e);//vlozeni vytvoreneho elementu do kolekce
            createPackagedElements(p);//volam na vnoreny balik
        }
        

        return eList;
    }

    
    
    //vyvori elements z polozek zahrnutych v baliku
    private void createPackagedElements(UcpPackage parentPackage){
    
        String parentID = parentPackage.getId();//ID rodicovskeho baliku
        
        //pro kazdy balik z kolekce rodicovskeho baliku
        for (UcpPackage p:parentPackage.getPList())
        {
            UcpElement e = new UcpElement();//novy ucp element
            
            e.setIdParent(parentID);//nastaveni ID rodicovskeho baliku
            e.setId(p.getId());//nastaveni ID baliku
            e.setName(p.getName());//nastaveni jmena baliku
            e.setType("uml:Package");//nastaveni typu elementu = balik
            
            e.setComplexity(p.getMetrics().getComplexity());//nastaveni complexity
            e.setHours(p.getMetrics().getHours());//nastaveni celkovych hodin
            e.setHoursPerUc(p.getMetrics().getHoursPerUc());//nastaveni hodin na ucp
            e.setHoursSW(p.getMetrics().getHoursSW());//nastaveni celkovych hodin podle Schneider Winters
            e.setSchneiderwinters(p.getMetrics().getSchneiderwinters());//cas podle Schneider Winters na jeden ucp
            e.setSubCasesHours(p.getMetrics().getSubCasesHours());//celkovy cas sub UseCases
            e.setSubCasesHoursSW(p.getMetrics().getSubCasesHoursSW());//celkovy cas sub UseCases podle Schneider Winters
            e.setUcp(p.getMetrics().getUcp());//nastaveni ucp
            e.setSubUCP(p.getMetrics().getSubUCP());//nastaveni sub ucp
            e.setSubUUCP(p.getMetrics().getSubUUCP());//nastaveni celkove complexity pro sub UseCases
            
            eList.add(e);//vlozeni vytvoreneho elementu do kolekce
            createPackagedElements(p);//rekurzivne volam na vnoreny balik
        }

        //pro kazdy useCase z kolekce rodicovskeho baliku
        for (UcpUseCase u:parentPackage.getUList())
        {
            UcpElement e = new UcpElement();//novy ucp element
            
            e.setIdParent(parentID);//nastaveni ID rodicovskeho baliku
            e.setId(u.getId());//nastaveni ID useCasu
            e.setName(u.getName());//nastaveni jmena useCasu
            e.setType("uml:UseCase");//nastaveni typu elementu = use case
            
            e.setComplexity(u.getMetrics().getComplexity());//nastaveni complexity
            e.setHours(u.getMetrics().getHours());//nastaveni celkovych hodin
            e.setHoursPerUc(u.getMetrics().getHoursPerUc());//nastaveni hodin na ucp
            e.setHoursSW(u.getMetrics().getHoursSW());//nastaveni celkovych hodin podle Schneider Winters
            e.setSchneiderwinters(u.getMetrics().getSchneiderwinters());//cas podle Schneider Winters na jeden ucp
            e.setSubCasesHours(u.getMetrics().getSubCasesHours());//celkovy cas sub UseCases
            e.setSubCasesHoursSW(u.getMetrics().getSubCasesHoursSW());//celkovy cas sub UseCases podle Schneider Winters
            e.setUcp(u.getMetrics().getUcp());//nastaveni ucp
            e.setSubUCP(u.getMetrics().getSubUCP());//nastaveni sub ucp
            e.setSubUUCP(u.getMetrics().getSubUUCP());//nastaveni celkove complexity pro sub UseCases
            
            eList.add(e);//vlozeni vytvoreneho elementu do kolekce
            createOwnedElements(u);//volam na vnoreny useCase
        }
        
        //pro kazdeho actora z kolekce rodicovskeho baliku
        for (UcpActor a:parentPackage.getAList())
        {
            UcpElement e = new UcpElement();//novy ucp element
            
            e.setIdParent(parentID);//nastaveni ID rodicovskeho baliku
            e.setId(a.getId());//nastaveni ID actora
            e.setName(a.getName());//nastaveni jmena actora
            e.setType("uml:Actor");//nastaveni typu elementu = actor
            
            e.setComplexity(a.getMetrics().getComplexity());//nastaveni complexity
            e.setHours(a.getMetrics().getHours());//nastaveni celkovych hodin
            e.setHoursPerUc(a.getMetrics().getHoursPerUc());//nastaveni hodin na ucp
            e.setHoursSW(a.getMetrics().getHoursSW());//nastaveni celkovych hodin podle Schneider Winters
            e.setSchneiderwinters(a.getMetrics().getSchneiderwinters());//cas podle Schneider Winters na jeden ucp
            e.setSubCasesHours(a.getMetrics().getSubCasesHours());//celkovy cas sub UseCases
            e.setSubCasesHoursSW(a.getMetrics().getSubCasesHoursSW());//celkovy cas sub UseCases podle Schneider Winters
            e.setUcp(a.getMetrics().getUcp());//nastaveni ucp
            e.setSubUCP(a.getMetrics().getSubUCP());//nastaveni sub ucp
            e.setSubUUCP(a.getMetrics().getSubUUCP());//nastaveni celkove complexity pro sub UseCases
            
            eList.add(e);//vlozeni vytvoreneho elementu do kolekce
        }
             
    
    }

    
    //vyvori elements z polozek zahrnutych v use case
    private void createOwnedElements(UcpUseCase parentUseCase){
    
        String parentID = parentUseCase.getId();//ID rodicovskeho useCasu
        
        //pro kazdy useCase z kolekce rodicovskeho useCasu
        for (UcpUseCase u:parentUseCase.getUList())
        {
            UcpElement e = new UcpElement();//novy ucp element
            
            e.setIdParent(parentID);//nastaveni ID rodicovskeho baliku
            e.setId(u.getId());//nastaveni ID useCasu
            e.setName(u.getName());//nastaveni jmena useCasu
            e.setType("uml:UseCase");//nastaveni typu elementu = use case
            
            e.setComplexity(u.getMetrics().getComplexity());//nastaveni complexity
            e.setHours(u.getMetrics().getHours());//nastaveni celkovych hodin
            e.setHoursPerUc(u.getMetrics().getHoursPerUc());//nastaveni hodin na ucp
            e.setHoursSW(u.getMetrics().getHoursSW());//nastaveni celkovych hodin podle Schneider Winters
            e.setSchneiderwinters(u.getMetrics().getSchneiderwinters());//cas podle Schneider Winters na jeden ucp
            e.setSubCasesHours(u.getMetrics().getSubCasesHours());//celkovy cas sub UseCases
            e.setSubCasesHoursSW(u.getMetrics().getSubCasesHoursSW());//celkovy cas sub UseCases podle Schneider Winters
            e.setUcp(u.getMetrics().getUcp());//nastaveni ucp
            e.setSubUCP(u.getMetrics().getSubUCP());//nastaveni sub ucp
            e.setSubUUCP(u.getMetrics().getSubUUCP());//nastaveni celkove complexity pro sub UseCases
            
            eList.add(e);//vlozeni vytvoreneho elementu do kolekce
            createOwnedElements(u);//rekurzivne volam na vnoreny useCase
        }
        
    }
    
    
}
