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

import java.util.Collection;
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 CustomDependencyPackage extends DependencyPackage ***REMOVED***

  public CustomDependencyPackage(Dependency d) ***REMOVED***
    super(d);
  ***REMOVED***

  private String getCustomRepositoryLocation(String ansibleRoot) ***REMOVED***
    return ansibleRoot+"/custom";
  ***REMOVED***

  /*
  public void serializeTo(String ansibleRoot) ***REMOVED***
    for(String mode:new String[]***REMOVED***"add", "remove", "update"***REMOVED***) ***REMOVED***
      ***REMOVED*** look for roles in the 'custom' repository
      try ***REMOVED***
        ***REMOVED*** role name
        String roleName = this.getDependency().getType()+"-"+this.getDependency().getName()+("add".equals(mode) ? "" : "-"+mode);
        ***REMOVED*** look for the custom role
        File src = new File(this.getCustomRepositoryLocation(ansibleRoot)+"/"+roleName);
        System.out.println("** CUSTOM ** " + src);
        if(src.exists()) ***REMOVED***
          ***REMOVED*** do copy
          System.out.println("copying CUSTOM role");
          File dest = new File(ansibleRoot+"/work/"+roleName);
          FileUtils.copyDirectory(src, dest);
        ***REMOVED***
      ***REMOVED*** catch(IOException e) ***REMOVED***
        e.printStackTrace();
      ***REMOVED***
    ***REMOVED***
  ***REMOVED***
  */
  
  public Collection<Role> getRoles(CustomRoleManager crm) ***REMOVED***
    Collection<Role> out = new Vector<>();
***REMOVED***    for(String mode:new String[]***REMOVED***"add", "remove", "update"***REMOVED***) ***REMOVED***
    for(String mode:new String[]***REMOVED***"add"***REMOVED***) ***REMOVED***  ***REMOVED*** "remove", "update"
      ***REMOVED*** role name
      String roleName = this.getDependency().getType()+"-"+this.getDependency().getName()+("add".equals(mode) ? "" : "-"+mode);
      try ***REMOVED***
        ***REMOVED*** look for custom role
        Role role = crm.getRole(roleName);
        if(role!=null) ***REMOVED***
          out.add(role);
        ***REMOVED***
      ***REMOVED*** catch (NoSuchElementException e) ***REMOVED***
***REMOVED***        e.printStackTrace();
        System.out.println("WARNING: no custom role found for " + roleName);
      ***REMOVED***
    ***REMOVED***
    return out;
  ***REMOVED***

  

***REMOVED***
