The Framework Skeleton

From Projectivity Documentation

Jump to: navigation, search
Go back to Framework Development Guide main section

This is a skeleton to start creating a new framework. You just have to copy this main class and start modifying it. For a more detailed example please refer to the Customer Management project.

package myframework;

import com.si.projectivity.auth.Authenticator;
import com.si.projectivity.core.Constants;
import com.si.projectivity.core.business.attachment.AttachmentDTO;
import com.si.projectivity.core.business.attachment.AttachmentGroupDTO;
import com.si.projectivity.core.business.attachment.StringMetaDataDTO;
import com.si.projectivity.core.business.resource.HumanResourceDTO;
import com.si.projectivity.core.business.role.WorkRoleDTO;
import com.si.projectivity.core.business.scope.definition.MentorStructuralScopeDefinitionDVO;
import com.si.projectivity.core.business.scope.definition.ScopeDefinitionName;
import com.si.projectivity.core.business.scope.definition.ScopeDefinitionServiceRemote;
import com.si.projectivity.core.business.scope.definition.ScopeDefinitionServiceRemoteHome;
import com.si.projectivity.core.business.scope.definition.ScopeDefinitionWorkRole;
import com.si.projectivity.core.business.scope.definition.StructuralTemplateDTO;
import com.si.projectivity.core.util.Pair;
import com.si.projectivity.core.util.ServiceLocator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

/**
 *
 * @author Me
 */
public class Main
{
    // Required services
    ScopeDefinitionServiceRemoteHome scopeDefHome = null;
    ScopeDefinitionServiceRemote     scopeDefSrv  = null;
    
    // The name and version of this framework
    private String STRUCURE_FRAMEWORK_NAME         = "My Framework";
    private int    STRUCURE_FRAMEWORK_VERSION      = 1;

    // Here define your ScopeDefinitionName Objects
    // private String companyName      = "Company";
    // private ScopeDefinitionName companyDefName      = new ScopeDefinitionName(STRUCURE_FRAMEWORK_NAME, companyName,      STRUCURE_FRAMEWORK_VERSION);
    
    // Here define your Company Roles
    // private WorkRoleDTO _partner            = null;
    
    // The framework is installed via a command line call
    public Main(String password) throws Exception
    {
        Authenticator.authenticate("admin", password);
        
        try
        {
            scopeDefHome = (ScopeDefinitionServiceRemoteHome) ServiceLocator.getInstance().getRemoteHome("ejb/Projectivity/ScopeDefinitionService");
            scopeDefSrv  = scopeDefHome.create();
        }
        catch(Throwable e)
        {
            e.printStackTrace();
            System.exit(1);
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception
    {
        if(args.length == 0)
        {
            System.out.println("Error: Admin password nedded");
            System.exit(1);
        }
        
        Main me = new Main(args[0]);
        
        me.createStructural(true);
        me.createProject(true);

        System.exit(0);
    }
    
    /**
     * In this method create all the structural elements of your framework    
     */    
    public void createStructural(boolean create) throws Exception
    {
        /*
        Date date = new Date();
        
        MentorStructuralScopeDefinitionDVO companyDVO = new MentorStructuralScopeDefinitionDVO();
        
        companyDVO.setKeyPrefix(Constants.KEY_PREFIX_SCOPE_DEFAULT_STRUCTURAL_DEPARTMENT);
        
        // ---------------------------------------------------------------------
        // ROLES
        // ---------------------------------------------------------------------
        // Company Roles
        
        _partner           = new WorkRoleDTO(null, "Partner", "Partner", 1, WorkRoleDTO.STAR_CARDINALITY);
        _partner.setScopeDefinition(companyDefName);
        
        ScopeDefinitionWorkRole partner           = new ScopeDefinitionWorkRole(_partner, HumanResourceDTO.SecurityRole.OWNER, false, 1, WorkRoleDTO.STAR_CARDINALITY);
        Collection<ScopeDefinitionWorkRole> companyRoles = new ArrayList<ScopeDefinitionWorkRole>();
        
        companyRoles.add(partner);
        companyDVO.setScopeDefinitionWorkRoles(companyRoles);
        
        // ---------------------------------------------------------------------
        //METADATA
        // ---------------------------------------------------------------------
        StringMetaDataDTO companyLegalName = new StringMetaDataDTO("softinstigate.company.name", date, "SoftInstigate Srl");
        companyLegalName.setMandatory(true);
        
        // ---------------------------------------------------------------------
        //TOOLS
        // ---------------------------------------------------------------------
        Collection<AttachmentGroupDTO> noTools  = new ArrayList<AttachmentGroupDTO>();
        
        Collection<AttachmentGroupDTO> tools  = new ArrayList<AttachmentGroupDTO>();
        AttachmentGroupDTO notes    = new AttachmentGroupDTO("Notes", "Notes",   AttachmentDTO.AttachmentType.NOTE);
        AttachmentGroupDTO meetings = new AttachmentGroupDTO("Meetings", "Meetings", AttachmentDTO.AttachmentType.MEETING);
        AttachmentGroupDTO tasks    = new AttachmentGroupDTO("Tasks", "Tasks",       AttachmentDTO.AttachmentType.TASK);
        tools.add(notes);
        tools.add(meetings);
        tools.add(tasks);
        
        companyDVO.setTools(tools);
        
        // ---------------------------------------------------------------------
        // ASSETS
        // ---------------------------------------------------------------------
        
        // CREATE ALL YOUR ASSETS HERE
        
        // ---------------------------------------------------------------------
        // WATCHES
        // ---------------------------------------------------------------------
        
        // CREATE ALL YOUR WATCHES HERE
        
        // ---------------------------------------------------------------------
        // CREATION OF THE FRAMEWORK
        // ---------------------------------------------------------------------
            
        Pair<Integer, Integer> zeroStar = new Pair<Integer, Integer>(0, -1);
        Pair<Integer, Integer> dueStar  = new Pair<Integer, Integer>(2, -1);
        
        StructuralTemplateDTO structuralFramework = new StructuralTemplateDTO(STRUCURE_FRAMEWORK_NAME, STRUCURE_FRAMEWORK_VERSION);
        
        Collection<Pair<ScopeDefinitionName, Pair<Integer, Integer>>> companyParents      = new ArrayList<Pair<ScopeDefinitionName, Pair<Integer, Integer>>>();
        
        companyParents.add(new Pair<ScopeDefinitionName, Pair<Integer, Integer>>(ScopeDefinitionName.getRootName(), zeroStar));
        
        structuralFramework.put2(companyDefName, companyDVO, companyParents);
        
        if (create)
        {
            // Now create the framework
            scopeDefSrv.createDefinition(structuralFramework);
        }
        
        System.out.println("Framework created");
        */
    }
 
    /**
     * Now create the project (if any)
     */
    public void createProject(boolean create) throws Exception
    {
    }
}