package org.gcube.dataanalysis.dataminer.poolmanager.ansiblebridge.template;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Vector;

import org.gcube.dataanalysis.dataminer.poolmanager.ansible.model.Role;
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency;

public class DependencyPackage ***REMOVED***

  private Dependency dependency;

  public DependencyPackage(Dependency d) ***REMOVED***
    this.dependency = d;
  ***REMOVED***

  protected Map<String, String> getDictionary(Dependency d) ***REMOVED***
    Map<String, String> out = new HashMap<String, String>();
    out.put("name", d.getName());
    out.put("type", d.getType());
    return out;
  ***REMOVED***
  
  protected Dependency getDependency() ***REMOVED***
    return this.dependency;
  ***REMOVED***
  
  public Collection<Role> getRoles(TemplateManager tm) ***REMOVED***
    Collection<Role> out = new Vector<>();
    for(String mode:new String[]***REMOVED***"add"***REMOVED***) ***REMOVED***  ***REMOVED*** "remove", "update"
      String roleName = this.getDependency().getType()+"-"+this.getDependency().getName().replaceAll("/",  "-")+("add".equals(mode) ? "" : "-"+mode);
      try ***REMOVED***
        ***REMOVED*** find template
        Role template = tm.getRoleTemplate(this.getDependency().getType()+"-package-"+mode);
        ***REMOVED*** 
        if(template!=null) ***REMOVED***
          Map<String, String> dictionary = this.getDictionary(this.getDependency());
          Role r = tm.fillRoleTemplate(template, dictionary);
          r.setName(roleName);
          out.add(r);
        ***REMOVED*** else ***REMOVED***
          System.out.println("WARNING: template is null");
        ***REMOVED***
      ***REMOVED*** catch (NoSuchElementException e) ***REMOVED***
***REMOVED***        e.printStackTrace();
        System.out.println("WARNING: no template found for " + roleName);
      ***REMOVED***
    ***REMOVED***
    return out;
  ***REMOVED***

***REMOVED***
