All pastes #448231 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-04-19 15:02 UTC
rendered paste body
MetadataManager metadataManager = Connector.getMetadataManager();
			PartyManager partyManager = Connector.getPartyManager();
			
		      // Now let's create an engineering department within Mega Corp.
			
		   //   String engineeringUuid = partyManager.createOrganization(m_rootAuth,
		     //                                                          "Engineering",
		       //                                                        "We design the stuff",
		         //                                                      m_kpRoot,   // Mega Corp is our 'parent' organization
		           //                                                    "Department",
		             //                                                  "eng@megacorp.com"); // email address for Engineering
			
			
//			 Now create a metadata template hierarchy.
		      // First get the root template UUID. The root template provides an optional root for the template hierarchy
		      // for a specific organization. Other templates don't have to inherit from the root template, but it's
		      // a good convention. Templates that don't inherit from the root template won't show up in the Administrator
		      // application.
		      String rootTemplateUuid = metadataManager.getRootMetadataTemplateUuid(m_userAuth, m_kpRoot);
		      
		      System.out.println("root Template uuid: " + rootTemplateUuid);
		      
		      // Create a label in the root template called 'Author' of type STRINGLIST - it may take multiple free-form strings
		      // as values. By adding the label in the root template, all other templates will inherit the label.
		      String authorLabelUuid = metadataManager.createMetadataLabelInTemplate(m_userAuth,
		                                                                             rootTemplateUuid,
		                                                                             "Author", // the 'Key'
		                                                                             true,     // required
		                                                                             DataType.STRINGLIST,
		                                                                             null, // default value
		                                                                             null); // max length

		      
		      System.out.println("author uuid: " + authorLabelUuid);
		      // Create a new template
		      String designDrawingsTemplateUuid = metadataManager.createTemplate(m_userAuth, "Design Drawings", m_kpRoot);

		      System.out.println("Desgin Drawing UUID: " + designDrawingsTemplateUuid);
		      
		      // Make the new template a child of the root template. It now inherits the "Author" label from the root template.
		      metadataManager.addChildTemplate(m_userAuth, rootTemplateUuid, designDrawingsTemplateUuid);

		      // Add labels to the new template
		      String statusLabelUuid = metadataManager.createMetadataLabelInTemplate(m_userAuth,
		                                                                             designDrawingsTemplateUuid,
		                                                                             "Design Status", // the 'Key'
		                                                                             true,     // required
		                                                                             DataType.PICKONE,
		                                                                             null, // default value
		                                                                             null); // max length

		      String inProgressSelectionUuid = metadataManager.createMetadataSelection(m_userAuth,
		                                                                               statusLabelUuid, DataType.STRING,
		                                                                               "In Progress", null );
		      String inRevisionSelectionUuid = metadataManager.createMetadataSelection(m_userAuth,
		                                                                               statusLabelUuid, DataType.STRING,
		                                                                               "In Revision", null );
		      String acceptedSelectionUuid = metadataManager.createMetadataSelection(m_userAuth,
		                                                                             statusLabelUuid, DataType.STRING,
		                                                                             "Accepted", null );
		      String rejectedSelectionUuid = metadataManager.createMetadataSelection(m_userAuth,
		                                                                             statusLabelUuid, DataType.STRING,
		                                                                             "Rejected", null );

		      // Create another template for the number of hours that have been spent on this drawing
		      String hoursWorkedLabelUuid = metadataManager.createMetadataLabelInTemplate(m_userAuth,
		                                                                                  designDrawingsTemplateUuid,
		                                                                                  "Hours Worked",
		                                                                                  false,
		                                                                                  DataType.NUMBER,
		                                                                                  null, // default value
		                                                                                  null); // max length                                                                                  );


		      // Create a new template that belongs to Joe himself. Creating a template that's owned by a
		      // user (as opposed to an organization or group) is not possible in the Admininstrator
		      // application, but it is allowed by the server.
		      String joesDrawingsTemplateUuid = metadataManager.createTemplate(m_userAuth,
		                                                                       "Joe's Design Work",
		                                                                       m_kpRoot);

		      
		      System.out.println("Joe drwaing Template UUID: " + joesDrawingsTemplateUuid);
		      
		      // Make Joe's new template a child of the "Design Drawings" template. Inter-organization
		      // relationships between metadata templates is another thing that isn't possible to create in
		      // the Administrator application at present, but it is allowed in the server and can be very useful.
		      metadataManager.addChildTemplate(m_userAuth, designDrawingsTemplateUuid, joesDrawingsTemplateUuid);

		      // Add a label to the template
		      String joesNotesLabelUuid = metadataManager.createMetadataLabelInTemplate(m_userAuth, joesDrawingsTemplateUuid,
		                                                                            "Joe's Notes",
		                                                                             true, DataType.NOTES,
		                                                                             null, // default value
		                                                                             null); // max length
              Collection templates = metadataManager.getChildTemplates(m_userAuth, rootTemplateUuid);
              Iterator iter = templates.iterator();
              while(iter.hasNext()) {
            	  MetadataTemplateInfo template = (MetadataTemplateInfo)iter.next();
            	  System.out.println("--> Template UUID: " + template.getUuid());
              }
		}