It's all about the answers!

Ask a question

Create new Attribute in DNG using API s


Vaibhav S (106247) | asked Apr 04 '17, 12:43 a.m.
edited Apr 04 '17, 3:02 a.m. by Muralidhar Rajagopal (10114)

Hi, I need to create a new Attribute in Artifact Attribute Tab in Project Properties Section in DNG using API s.

Please let me know the useful API s in case its possible to do so.

Thanks
Vaibhav

One answer



permanent link
Vaibhav S (106247) | answered Nov 10 '17, 3:07 a.m.
edited Nov 10 '17, 3:09 a.m.

package org.rb.com.artifact;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URI;
import java.net.URISyntaxException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.wink.client.ClientResponse;
import org.eclipse.lyo.client.exception.JazzAuthFailedException;
import org.eclipse.lyo.client.exception.ResourceNotFoundException;
import org.eclipse.lyo.client.exception.RootServicesException;
import org.eclipse.lyo.client.oslc.OslcClient;
import org.eclipse.lyo.client.oslc.jazz.JazzFormAuthClient;
import org.eclipse.lyo.client.oslc.jazz.JazzRootServicesHelper;
import org.eclipse.lyo.client.oslc.resources.Requirement;
import org.eclipse.lyo.client.oslc.resources.RmConstants;
import org.eclipse.lyo.client.oslc.resources.RmUtil;
import org.eclipse.lyo.oslc4j.core.model.ResourceShape;
import org.w3c.dom.Element;

import net.oauth.OAuthException;

public class CreateArtifactCLI extends JFrame implements ActionListener {
    JButton SUBMIT;
    JPanel panel;
    JLabel label1;
    JLabel label2;
 
    static JTextField text1;
    static JTextField text2;
    static String value1= "";
    static String value2= "";
    static String rtcURL;
    static String projectArea;
    static String projectAreaPathVar;
    static String requiremntType;
    static String title;
    static String description;
    static CreateArtifactCLI objCLI;
    
   

    CreateArtifactCLI() {
        System.out.println("constructor hit ...");
        
        JFrame frame = new JFrame("JFrame Example");

        JPanel panel = new JPanel();
        
        this.label1 = new JLabel();
        this.label1.setText("Username:");
        text1 = new JTextField(15);
        
        this.label2 = new JLabel();
        this.label1.setText("Password:");
        text2 = new JPasswordField(15);
        
        JButton button = new JButton();
        button.setText("Submit");

        panel.add(label1);
        panel.add(label2);
        panel.add(button);

        frame.add(panel);
        frame.setSize(300, 300);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        
        
       / this.label1 = new JLabel();
        this.label1.setText("Username:");
        text1 = new JTextField(15);
     
        this.label2 = new JLabel();
        text2 = new JPasswordField(15);
      
        this.SUBMIT = new JButton("SUBMIT");
        this.panel = new JPanel(new GridLayout(3, 1));
        this.panel.add(this.label1);
        this.panel.add(text1);
        this.panel.add(this.label2);
        this.panel.add(text2);
        this.panel.add(this.SUBMIT);
   //     frame
        this.add((Component)this.panel, "Center");
        
        System.out.println("calling button click now ...");
       
        value1 = text1.getText();
        value2 = text2.getText();
      
       
        
        JFrame frame1 = new JFrame("frame");
        frame1.setSize(300, 100);
        frame1.setVisible(true);
/
       
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation(dim.width / 2 - CreateArtifactCLI.objCLI.getSize().width / 2, dim.height / 2 - CreateArtifactCLI.objCLI.getSize().height / 2);

        this.SUBMIT.addActionListener(this);
        this.setTitle("LOGIN FORM");
        
    }

    
    @Override
    public void actionPerformed(ActionEvent arg0) {
        System.out.println("In listener ....");
        
   //     rtcURL = "";
   //     projectArea = "playground(RM)";
        
        value1 = text1.getText();
        value2 = text2.getText();
   //     objCLI.dispose();
        
    }
 
    
    public static void main(String[] args) throws RootServicesException, JazzAuthFailedException, ResourceNotFoundException, IOException, OAuthException, URISyntaxException, ParserConfigurationException {
        System.out.println("In main method ...");
      
        objCLI = new CreateArtifactCLI();
        
               
        System.out.println("creating frame now ....");
                      
        rtcURL = args[0];
        projectArea = args[1];
        projectAreaPathVar = null;
        requiremntType = args[2];
        title = args[3];
        description = args[4];
        
  //      value1 = text1.getText();
  //      value2 = text2.getText();
        
        
        
        objCLI.connect(rtcURL, value1, value2);
    }

    
    @SuppressWarnings("unchecked")
    public void connect(String rtcURL, String value1, String value2) {
        try {
            JazzRootServicesHelper helper = new JazzRootServicesHelper(rtcURL, "http://open-services.net/ns/rm#");
            JazzFormAuthClient client = helper.initFormClient(value1, value2, rtcURL);
          
            if (client.formLogin() == 200) {
                System.out.println("Login SUCCESS!");
            }
            
            final PrintStream err = new PrintStream(System.err);
            System.setErr(new PrintStream("/dev/null"));
            String catalogUrl = helper.getCatalogUrl();
         
            System.out.println("catalogUrl: " + catalogUrl);
            
        //  final PrintStream err = new PrintStream(System.err);
        
            String serviceProviderUrl = client.lookupServiceProviderUrl(catalogUrl, projectArea);
           
            System.out.println("serviceProviderUrl: " + serviceProviderUrl);
            
            int pos1 = serviceProviderUrl.indexOf("oslc_rm/");
            int pos2 = serviceProviderUrl.indexOf("services.xml");
            int pos3 = catalogUrl.indexOf("catalog");
          
            String sub = serviceProviderUrl.substring(pos1 + 8, pos2 - 1);
          
            String catalogURLVar = catalogUrl.substring(0, pos3 - 1);
          
            projectAreaPathVar = String.valueOf(catalogURLVar) + "/process/process-area/" + sub;
            System.out.println("projectAreaPathVar: " + projectAreaPathVar);
           
        
            String requirementFactory = client.lookupCreationFactory(serviceProviderUrl, "http://open-services.net/ns/rm#", "http://open-services.net/ns/rm#Requirement");
            System.setErr(err);
            
            URI projectAreaPath = new URI(projectAreaPathVar);
           
            ResourceShape featureInstanceShape = RmUtil.lookupRequirementsInstanceShapes((String)serviceProviderUrl,
                    (String)"http://open-services.net/ns/rm#", (String)"http://open-services.net/ns/rm#Requirement", (OslcClient)client,
                    (String)requiremntType);
           
            Requirement requirement = new Requirement();
            requirement.setInstanceShape(featureInstanceShape.getAbout());
            requirement.setTitle(title);
            requirement.setDescription(description);
            requirement.setServiceProvider(projectAreaPath);
          
            String primaryText = "Test Primary Text";
           
            Element obj = RmUtil.convertStringToHTML((String)primaryText);
            requirement.getExtendedProperties().put(RmConstants.PROPERTY_PRIMARY_TEXT, obj);
           
            ClientResponse response = client.createResource(requirementFactory, (Object)requirement, "application/rdf+xml", "application/rdf+xml");
            System.out.println("done ...........");
           
            if (response.getStatusCode() == 200 || response.getStatusCode() == 201) {
                System.out.println("Requirement Created");
            }
            
            else {
                System.out.println("Requirement Not Created");
            }
        }
        catch (Exception e) {
            System.out.println("Please enter correct user id and password");
        }
    }


}

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.