└── TestP6API ├── .gitignore ├── src └── demo │ ├── .gitignore │ ├── A00_APIConfig.java │ ├── A02_Session.java │ ├── B03_ProjectObjectId.java │ ├── B02_EPS_Project.java │ ├── B04_Activity.java │ ├── A01_DBInstance.java │ ├── B01_Project.java │ └── B05_ProjectCode.java ├── .classpath └── .project /TestP6API/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /TestP6API/src/demo/.gitignore: -------------------------------------------------------------------------------- 1 | /A00_APIConfig.properties 2 | -------------------------------------------------------------------------------- /TestP6API/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /TestP6API/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | TestP6API 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /TestP6API/src/demo/A00_APIConfig.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import java.util.ResourceBundle; 4 | 5 | public class A00_APIConfig { 6 | 7 | private static final ResourceBundle bundle = ResourceBundle.getBundle(A00_APIConfig.class.getName()); 8 | 9 | public static String remoteServerHost = bundle.getString("REMOTE_SERVER_HOST"); 10 | public static String remoteServerPort = bundle.getString("REMOTE_SERVER_PORT"); 11 | public static String p6UserName = bundle.getString("P6_API_USER");; 12 | public static String p6Password = bundle.getString("P6_API_PASSWORD");; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /TestP6API/src/demo/A02_Session.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import com.primavera.ServerException; 4 | import com.primavera.integration.client.ClientException; 5 | import com.primavera.integration.client.Session; 6 | import com.primavera.integration.common.DatabaseInstance; 7 | import com.primavera.integration.network.NetworkException; 8 | 9 | public class A02_Session { 10 | 11 | /** 12 | * Use P6 Integration API user account (not database user) to log into P6 13 | * 14 | * @param args 15 | * @throws ClientException 16 | * @throws NetworkException 17 | * @throws ServerException 18 | */ 19 | public static void main(String[] args) throws ServerException, NetworkException, ClientException { 20 | 21 | DatabaseInstance[] dbInstances = Session.getDatabaseInstances(A01_DBInstance.getRmiUrl()); 22 | Session session = A02_Session.getSession(dbInstances); 23 | 24 | System.out.println(session); 25 | } 26 | 27 | public static Session getSession(DatabaseInstance[] dbInstances) throws ServerException, NetworkException, ClientException { 28 | return Session.login(A01_DBInstance.getRmiUrl(), dbInstances[p6DBIndex].getDatabaseId(), p6UserName, p6Password); 29 | } 30 | 31 | private static int p6DBIndex = 1; 32 | private static String p6UserName = A00_APIConfig.p6UserName; 33 | private static String p6Password = A00_APIConfig.p6Password; 34 | } 35 | -------------------------------------------------------------------------------- /TestP6API/src/demo/B03_ProjectObjectId.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import com.primavera.ServerException; 4 | import com.primavera.common.value.ObjectId; 5 | import com.primavera.integration.client.ClientException; 6 | import com.primavera.integration.client.EnterpriseLoadManager; 7 | import com.primavera.integration.client.Session; 8 | import com.primavera.integration.client.bo.object.Project; 9 | import com.primavera.integration.common.DatabaseInstance; 10 | import com.primavera.integration.network.NetworkException; 11 | 12 | public class B03_ProjectObjectId { 13 | 14 | /** 15 | * If you know the primary key of a object, you can use it load it via 16 | * ObjectId. For example, if you know the primary key of a project, you can 17 | * use it to load this project 18 | * 19 | * @param args 20 | * @throws ClientException 21 | * @throws NetworkException 22 | * @throws ServerException 23 | */ 24 | public static void main(String[] args) throws ServerException, NetworkException, ClientException { 25 | 26 | DatabaseInstance[] dbInstances = Session.getDatabaseInstances(A01_DBInstance.getRmiUrl()); 27 | Session session = A02_Session.getSession(dbInstances); 28 | EnterpriseLoadManager elm = session.getEnterpriseLoadManager(); 29 | 30 | // there are two basic way to create an ObjectId 31 | ObjectId objectId = new ObjectId(90311); 32 | // objectId = ObjectId.fromString("90311"); 33 | 34 | Project project = Project.load(session, new String[] { "Id", "Name" }, objectId); 35 | 36 | System.out.printf("Project[%s] : %s | %s\n", project.getObjectId(), project.getId(), project.getName()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /TestP6API/src/demo/B02_EPS_Project.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import com.primavera.ServerException; 4 | import com.primavera.integration.client.ClientException; 5 | import com.primavera.integration.client.EnterpriseLoadManager; 6 | import com.primavera.integration.client.Session; 7 | import com.primavera.integration.client.bo.BOIterator; 8 | import com.primavera.integration.client.bo.object.EPS; 9 | import com.primavera.integration.client.bo.object.Project; 10 | import com.primavera.integration.common.DatabaseInstance; 11 | import com.primavera.integration.network.NetworkException; 12 | 13 | public class B02_EPS_Project { 14 | 15 | /** 16 | * Enterprise Load Manager provides functions to access main P6 objects, eg: 17 | * Project, Activity, Resource, EPS, WBS, Codes, UDFs. 18 | * 19 | * @param args 20 | * @throws ClientException 21 | * @throws NetworkException 22 | * @throws ServerException 23 | */ 24 | public static void main(String[] args) throws ServerException, NetworkException, ClientException { 25 | 26 | DatabaseInstance[] dbInstances = Session.getDatabaseInstances(A01_DBInstance.getRmiUrl()); 27 | Session session = A02_Session.getSession(dbInstances); 28 | EnterpriseLoadManager elm = session.getEnterpriseLoadManager(); 29 | 30 | BOIterator boiEPS = elm.loadEPS(new String[] { "Id", "Name" }, "Id like '%THP%'", null); 31 | while (boiEPS.hasNext()) { 32 | EPS eps = boiEPS.next(); 33 | 34 | System.out.println("EPS = " + eps.getId() + ", " + eps.getName()); 35 | 36 | BOIterator boiProject = eps.loadProjectChildren(new String[] { "Id", "Name" }, null, null); 37 | while (boiProject.hasNext()) { 38 | Project project = boiProject.next(); 39 | 40 | System.out.printf("\tProject[%s] : %s | %s\n", project.getObjectId(), project.getId(), project.getName()); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /TestP6API/src/demo/B04_Activity.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import com.primavera.ServerException; 4 | import com.primavera.common.value.ObjectId; 5 | import com.primavera.integration.client.ClientException; 6 | import com.primavera.integration.client.EnterpriseLoadManager; 7 | import com.primavera.integration.client.Session; 8 | import com.primavera.integration.client.bo.BOIterator; 9 | import com.primavera.integration.client.bo.object.Activity; 10 | import com.primavera.integration.client.bo.object.Project; 11 | import com.primavera.integration.common.DatabaseInstance; 12 | import com.primavera.integration.network.NetworkException; 13 | 14 | public class B04_Activity { 15 | 16 | /** 17 | * 18 | * @param args 19 | * @throws ClientException 20 | * @throws NetworkException 21 | * @throws ServerException 22 | */ 23 | public static void main(String[] args) throws ServerException, NetworkException, ClientException { 24 | 25 | DatabaseInstance[] dbInstances = Session.getDatabaseInstances(A01_DBInstance.getRmiUrl()); 26 | Session session = A02_Session.getSession(dbInstances); 27 | EnterpriseLoadManager elm = session.getEnterpriseLoadManager(); 28 | 29 | // there are two basic way to create an ObjectId 30 | ObjectId objectId = new ObjectId(90311); 31 | // objectId = ObjectId.fromString("90311"); 32 | 33 | Project project = Project.load(session, new String[] { "Id", "Name" }, objectId); 34 | 35 | System.out.printf("Project[%s] : %s | %s\n", project.getObjectId(), project.getId(), project.getName()); 36 | 37 | BOIterator boiActivity = project.loadAllActivities(new String[] { "Id", "Name" }, null, null); 38 | while (boiActivity.hasNext()) { 39 | Activity activity = boiActivity.next(); 40 | 41 | System.out.printf("\tActivity[%s] : %s | %s\n", activity.getObjectId(), activity.getId(), activity.getName()); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /TestP6API/src/demo/A01_DBInstance.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import com.primavera.ServerException; 4 | import com.primavera.integration.client.ClientException; 5 | import com.primavera.integration.client.RMIURL; 6 | import com.primavera.integration.client.Session; 7 | import com.primavera.integration.common.DatabaseInstance; 8 | import com.primavera.integration.network.NetworkException; 9 | 10 | public class A01_DBInstance { 11 | 12 | /** 13 | * Demo how to use LocalMode/RemoteMode to get DB Instances. Review DB 14 | * Instance information to make sure you are connecting to the right P6 15 | * database 16 | * 17 | * @param args 18 | * @throws ClientException 19 | * @throws NetworkException 20 | * @throws ServerException 21 | */ 22 | public static void main(String[] args) throws ServerException, NetworkException, ClientException { 23 | 24 | DatabaseInstance[] dbInstances = Session.getDatabaseInstances(A01_DBInstance.getRmiUrl()); 25 | 26 | printDBInstance(dbInstances); 27 | } 28 | 29 | public static String getRmiUrl() { 30 | if (isRemoteMode) 31 | return RMIURL.getRmiUrl(RMIURL.STANDARD_RMI_SERVICE, remoteServerHost, remoteServerPort); 32 | else 33 | return RMIURL.getRmiUrl(RMIURL.LOCAL_SERVICE); 34 | } 35 | 36 | private static boolean isRemoteMode = true; 37 | private static String remoteServerHost = A00_APIConfig.remoteServerHost; 38 | private static int remoteServerPort = Integer.parseInt(A00_APIConfig.remoteServerPort); 39 | 40 | public static void printDBInstance(DatabaseInstance[] dbInstances) { 41 | for (DatabaseInstance databaseInstance : dbInstances) { 42 | System.out.println("DatabaseId=" + databaseInstance.getDatabaseId()); 43 | System.out.println("ActualDatabaseName=" + databaseInstance.getActualDatabaseName()); 44 | System.out.println("DatabaseUrl=" + databaseInstance.getDatabaseUrl()); 45 | System.out.println("DatabaseName=" + databaseInstance.getDatabaseName()); 46 | System.out.println("*******************************************"); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /TestP6API/src/demo/B01_Project.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import com.primavera.ServerException; 4 | import com.primavera.integration.client.ClientException; 5 | import com.primavera.integration.client.EnterpriseLoadManager; 6 | import com.primavera.integration.client.Session; 7 | import com.primavera.integration.client.bo.BOIterator; 8 | import com.primavera.integration.client.bo.object.Project; 9 | import com.primavera.integration.common.DatabaseInstance; 10 | import com.primavera.integration.network.NetworkException; 11 | 12 | public class B01_Project { 13 | 14 | /** 15 | * Enterprise Load Manager provides functions to access main P6 objects, eg: 16 | * Project, Activity, Resource, EPS, WBS, Codes, UDFs. 17 | * 18 | * @param args 19 | * @throws ClientException 20 | * @throws NetworkException 21 | * @throws ServerException 22 | */ 23 | public static void main(String[] args) throws ServerException, NetworkException, ClientException { 24 | 25 | DatabaseInstance[] dbInstances = Session.getDatabaseInstances(A01_DBInstance.getRmiUrl()); 26 | Session session = A02_Session.getSession(dbInstances); 27 | 28 | EnterpriseLoadManager elm = session.getEnterpriseLoadManager(); 29 | 30 | // field to load, must match the method name getXXX() 31 | String[] fields = { "Id", "Name" }; 32 | // filter, similar to SQL where clause 33 | String whereClause = "Id like 'C.9%'"; 34 | // order by, similar to SQL order by 35 | String orderBy = "Id asc"; 36 | 37 | // use while, .hasNext(), .next() to loop each project from BOIerator 38 | BOIterator boiProject = elm.loadProjects(fields, whereClause, orderBy); 39 | while (boiProject.hasNext()) { 40 | Project project = boiProject.next(); 41 | 42 | // you must load Id, Name 43 | System.out.println("Project = " + project.getId() + ", " + project.getName()); 44 | 45 | // ObjectId is the database table primary key 46 | // you don't need to load it 47 | System.out.println("Project ObjectId = " + project.getObjectId()); 48 | 49 | // you will get error, if you did not load it 50 | // System.out.println(project.getDataDate()); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /TestP6API/src/demo/B05_ProjectCode.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import com.primavera.ServerException; 4 | import com.primavera.integration.client.ClientException; 5 | import com.primavera.integration.client.EnterpriseLoadManager; 6 | import com.primavera.integration.client.Session; 7 | import com.primavera.integration.client.bo.BOIterator; 8 | import com.primavera.integration.client.bo.object.ProjectCode; 9 | import com.primavera.integration.client.bo.object.ProjectCodeAssignment; 10 | import com.primavera.integration.client.bo.object.ProjectCodeType; 11 | import com.primavera.integration.common.DatabaseInstance; 12 | import com.primavera.integration.network.NetworkException; 13 | 14 | public class B05_ProjectCode { 15 | 16 | /** 17 | * @param args 18 | * @throws ClientException 19 | * @throws NetworkException 20 | * @throws ServerException 21 | */ 22 | public static void main(String[] args) throws ServerException, NetworkException, ClientException { 23 | 24 | DatabaseInstance[] dbInstances = Session.getDatabaseInstances(A01_DBInstance.getRmiUrl()); 25 | Session session = A02_Session.getSession(dbInstances); 26 | EnterpriseLoadManager elm = session.getEnterpriseLoadManager(); 27 | 28 | // load a project code type 29 | BOIterator boiProjectCodeType = elm.loadProjectCodeTypes(ProjectCodeType.getAllFields(), "ObjectId=49", null); 30 | while (boiProjectCodeType.hasNext()) { 31 | ProjectCodeType codeType = boiProjectCodeType.next(); 32 | 33 | System.out.printf("CodeType[%s] %s\n", codeType.getObjectId(), codeType.getName()); 34 | 35 | // load its project code values 36 | BOIterator boiProjectCode = codeType.loadAllProjectCodes(ProjectCode.getAllFields(), null, null); 37 | while (boiProjectCode.hasNext()) { 38 | ProjectCode code = boiProjectCode.next(); 39 | 40 | System.out.printf("\tCode[%s] %s | %s\n", code.getObjectId(), code.getCodeValue(), code.getDescription()); 41 | 42 | // show project code assignment for a certain code 43 | if (314 == code.getObjectId().toInteger().intValue()) { 44 | BOIterator boiCodeProject = code.loadProjectCodeAssignments(ProjectCodeAssignment.getAllFields(), null, null); 45 | 46 | while (boiCodeProject.hasNext()) { 47 | ProjectCodeAssignment codeProject = boiCodeProject.next(); 48 | 49 | System.out.printf("\t\tCodeAssignment[%s] %s | %s\n", codeProject.getProjectObjectId(), codeProject.getProjectId(), 50 | codeProject.getProjectName()); 51 | } 52 | } 53 | } 54 | } 55 | } 56 | } 57 | --------------------------------------------------------------------------------