====== Schnittstellen Entwicklung für Oracle Primavera P6 R8.2 mit der P6 Integration API ====== Mit P6 Integration API steht eine Java Klassen Bibliothek für den Zugriff auf die Primavera Objekte zur Verfügung. Die Klassen können im lokalen Mode direkt mit der Datenbank von Primavera "reden", im Remote Mode wird eine Server Architektur mit einem RMI Server als Mittelschicht zwischen der Schnittstellen Applikation und der Datenbank implementiert. === Die Basis Klassen === **Session**: \\ Verbindungsaufbau zur Datenbank **GlobalObjectManager**: \\ " The Global Object Manager is used for accessing all global business objects: EPS, Projects, Resources, Roles, etc. Generally speaking, a business object is global if it is not a child of a different type of object. The GlobalObjectManager is retrieved for a particular session by calling Session.getGlobalObjectManager() From the GlobalObjectManager, global objects can be created, loaded, updated, and deleted. Create, update, and delete will cause the database to be updated. When running in remote mode, each of these methods results in a call across the wire to the server, which in turn can update the database " **EnterpriseLoadManager**: \\ "The Enterprise Load Manager is used for loading all types of business objects directly with an optional where clause. The EnterpriseLoadManager is retrieved for a particular session by calling Session.getEnterpriseLoadManager()" **Business Objects wie Project, WBS etc**: \\ "A business object is an encapsulation of business data and functionality that usually corresponds to a record in a particular database table. Business objects contain fields, exposed as properties. Get() methods exist for all fields, and set() methods exist only for writable fields. Most business objects contain an ObjectId field, which serves as the primary key for that object. " **XMLExporter** \\ Exportieren in das Primvera XML Export Format. **XMLImporter** \\ Importieren in das Primvera XML Export Format. === Installation der API === Vorbereitung: * Java JDK 1.6 u39 installiert * [[http://www.oracle.com/technetwork/developer-tools/jdev/downloads/index.html|Oracle JDeveloper]] (Java Edition: 11.1.2.3.0 sollte reichen) oder ähnliche Entwicklungsumgebung Installation der Primavera P6 Integration API R8.2 for Microsoft Windows aus dem Packet V29694-01.zip: Entpacken und Start des Installers setup.exe unter .\P6_R82_Integration_API\Disk1\install * Startbildschirm * Next * Local Mode Packages * Next * Pfad zum Produktverzeichniss angeben ( zum Beispiel D:\oracle\product\P6IntegrationAPI1 ) * Next * Alle Produkte anwählen * Next * Java JDK Home angeben * Next * Summary * Install * Installationsvorgang läuft durch * Database Configuration Wizard startet * Oracle auswählen * Connection Dialog ausfüllen * Bestehende Konfiguration verwenden * Installation ist beendet === Ein erstes Demo Programm === JDeveloper Java Edition unter d:\entwicklung\jdeveloper entpacken und jdeveloper.exe starten und beim ersten Start die passende Java.exe (wiee C:\Programme\Java\jdk1.6.0_39\bin\java.exe ) aus dem JDK Verzeichniss auswählen. JDeveloper starten und über "Tools"/"Manage Libraries" intgeserver.jar und intgclient.jar als Library hinterlegen. dort kann auch der Pfad zur Java Doc der APi hinterlegt werden und kann damit direkt über den JDeveloper aufgerufen werden. Um den Connect zur Datenbank zu finden benötigt die Library den Pfad zur BREBootStrap.xml, diesen Pfad in den Run Optionen mit "-Dprimavera.bootstrap.home=D:\\oracle\\product\\P6IntegrationAPI" hinterlegen. Das erste Demo Programm meldet sich an der DB an und gibt die Projekte in der Datenbank und die WBS dazu aus. import com.primavera.integration.client.Session; import com.primavera.integration.client.EnterpriseLoadManager; import com.primavera.integration.client.RMIURL; import com.primavera.integration.common.DatabaseInstance; import com.primavera.integration.client.bo.BOIterator; import com.primavera.integration.client.bo.object.Project; import com.primavera.integration.client.bo.object.WBS; public class DBConnect { public static void main(String[] args) { Session session = null; try { // Zugriff auf die Datenbanken im System // Hinterlegt in der Zugangskonfiguration BREBootStrap.xml // Pfad zu der Datei wird das Parameter übergeben -Dprimavera.bootstrap.home=D:\\oracle\\product\\P6IntegrationAPI1 DatabaseInstance[] dbInstances = Session.getDatabaseInstances(RMIURL.getRmiUrl(RMIURL.LOCAL_SERVICE)); System.out.println("Info -- Anzahl der gefundenen Primavera Instancen :: "+ dbInstances.length); // Verwende die erste Datenbank String username="admin"; String pwd="Prima2013"; // Anmelden an Primavera session = Session.login(RMIURL.getRmiUrl(RMIURL.LOCAL_SERVICE), dbInstances[0].getDatabaseId(), username, pwd); // Business Object Manager laden EnterpriseLoadManager elm = session.getEnterpriseLoadManager(); // Alle Projekt Referenzen laden BOIterator boi = elm.loadProjects(new String[] { "Name" ,"Id"}, null, "Name asc"); // Projekte ausgeben while (boi.hasNext()) { Project proj = boi.next(); System.out.println("Info ----------------------------------------"); System.out.println("Info -- Projekt["+proj.getId()+"]"+proj.getName()); // WPS Struktur des Projektes anzeigen BOIterator wbsi = proj.loadAllWBS( new String[] { "Code","Name" }, null, "Code asc") ; while (wbsi.hasNext()) { WBS wbs = wbsi.next(); System.out.println(" + WBS ["+wbs.getCode()+"]"+wbs.getName()); } } } catch (Exception e) { // einfacher Exeption handler für das Demo // Produktiv muss das erweitert werden e.printStackTrace(); } finally { // wieder abmelden if (session != null) session.logout(); } } } ==== Kalender Einträge in Primavera aktualisieren ==== Idee: Lesen der *.ica Files über [[http://wiki.modularity.net.au/ical4j/index.php?title=Main_Page|ical4j]] und schreiben in die Datenbank. Siehe auch Support Node [ID 1280526.1] zu dem Thema. ==== Dokumentation ==== Local liegt im Installationsverzeichnis unter docs die Java API Dokumentation. Anwendung der P6 Integration API * http://docs.oracle.com/cd/E25030_01/English/Integration_Documentation/Integration_API/Doc/index.htm Übersicht über die Klassen * http://docs.oracle.com/cd/E25030_01/English/Integration_Documentation/Integration_API/Java_doc/index.html Support Nodes * Create Calendar Exceptions Using P6 Integration API [ID 1280526.1] ===== Quellen ===== JDeveloper: * http://www.oracledistilled.com/java/adding-java-libraries-to-oracle-jdeveloper-11g-r1/ Primavera: * http://usingp6.com/programmer/2011/01/06/a-script-to-run-a-p6-integration-api-application.html * http://usingp6.com/programmer/2011/02/08/starting-the-java-api-with-primavera-p6.html {{tag>primaveraarchitektur}}