Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

datamodel for qm

Hi
I'm trying to modify the datamodel for cm to fit qm. I'm looking at the OSLC workshop.
This is what I've written. Does it look correct?

/*******************************************************************************
 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corporation 2010, 2011. All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:  Use,
 * duplication or disclosure restricted by GSA ADP Schedule
 * Contract with IBM Corp.
 *******************************************************************************/
package net.jazz.oslc.cm.datamodel;

import java.io.IOException;
import java.io.Writer;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class TestPlan {
    String uri;
    String dcTitle;
    String dcIdentifier;
    String dcType;
    String dcDescription;
    String dcSubject;
    String dcCreator;
    Date dcModified;
    
    static final String CM_TITLE = "dcterms:title";
    static final String CM_IDENTIFIER = "dcterms:identifier";
    static final String CM_TYPE = "dcterms:type";
    static final String CM_DESCRIPTION = "dcterms:description";
    static final String CM_SUBJECT = "dcterms:subject";
    static final String CM_CREATOR = "dcterms:creator";
    static final String CM_MODIFIED = "dcterms:modified";
    static final String CM_ABOUT = "rdf:about";
    
    //static SimpleDateFormat RFC3339Format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    //static SimpleDateFormat RFC3339DecFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
    /**
     * Creates a Test Plan based on the DOM structure
     */
    public TestPlan(String uri, Element element) {
        super();
        this.uri = uri;
        this.dcTitle = getChildContent(element, CM_TITLE);
        this.dcIdentifier = getChildContent(element, CM_IDENTIFIER);
        this.dcType = getChildContent(element, CM_TYPE);
        this.dcDescription = getChildContent(element, CM_DESCRIPTION);
        this.dcSubject = getChildContent(element, CM_SUBJECT);
        this.dcCreator = getChildContent(element, CM_CREATOR);
        /*String dateString = getChildContent(element, CM_MODIFIED);
        try {
            this.dcModified = RFC3339Format.parse(dateString);
        } catch (ParseException e) {
            //try again with optional decimals
            //RFC3339DecFormat.setLenient(true);
            try {
                this.dcModified = RFC3339DecFormat.parse(dateString);
            } catch (ParseException ee) {
                this.dcModified = new Date();
            }
        }*/
    }
    /**
     * Generates the XML representation of the receiver
     */
    public void writeXML(Writer out) throws IOException {
        out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        out.append("<rdf:RDF\n");
        out.append("\t\txmlns:dcterms=\"http://purl.org/dc/terms/\"\n");
        out.append("\t\txmlns::rqm_auto=\"http://jazz.net/ns/auto/rqm#\"\n");
        out.append("\t\txmlns:oslc_qm=\"http://open-services.net/ns/qm#\"\n");
        out.append("\t\txmlns:rqm_qm=\"http://jazz.net/ns/qm/rqm#\"\n");
        out.append("\t\txmlns:calm=\"http://jazz.net/xmlns/prod/jazz/calm/1.0/\"\n");
        out.append("\t\txmlns:oslc=\"http://open-services.net/ns/core#\"\n");
        out.append("\t\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n");
        out.append("\t\txmlns:acp=\"http://jazz.net/ns/acp#\"\n");
        out.append("\t\txmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n");
        out.append("\t\txmlns:foaf=\"http://xmlns.com/foaf/0.1/\"\n");
        out.append("\t\txmlns:oslc_auto=\"http://open-services.net/ns/auto#\"\n");
        out.append("\t\txmlns:bp=\"http://open-services.net/ns/basicProfile#\">\n");
        out.append("\t<oslc_qm:testPlan\n");
        if (uri != null) {
            //out.append("\n\t\trdf:resource=\""+uri+"\">\n");
            out.append("\n\t\trdf:about=\""+uri+"\">\n");
        } else {
            out.append(">\n");
        }
        appendXMLAttribute(out, CM_TITLE, dcTitle);
        appendXMLAttribute(out, CM_IDENTIFIER, dcIdentifier);
        appendXMLAttribute(out, CM_TYPE, dcType);
        appendXMLAttribute(out, CM_DESCRIPTION, dcDescription);
        appendXMLAttribute(out, CM_SUBJECT, dcSubject);
        appendXMLAttribute(out, CM_CREATOR, dcCreator);
        //appendXMLAttribute(out, CM_MODIFIED, RFC3339Format.format(dcModified));
        out.append("\t</oslc_qm:testPlan>\n");
        out.append("</rdf:RDF>\n");
        out.flush();
    }
    private void appendXMLAttribute(Writer out, String id, String value) throws IOException {
        out.append("\t<"+id+">"+value+"</"+id+">\n");
    }
    /**
     * Generates the JSON representation of the receiver
     */
    public void writeJSON(Writer out) throws IOException {
        out.append("{\n");
        if (uri != null)
        appendJSONAttribute(out, CM_ABOUT, uri);
        appendJSONAttribute(out, CM_TITLE, dcTitle);
        appendJSONAttribute(out, CM_IDENTIFIER, dcIdentifier);
        appendJSONAttribute(out, CM_TYPE, dcType);
        appendJSONAttribute(out, CM_DESCRIPTION, dcDescription);
        appendJSONAttribute(out, CM_SUBJECT, dcSubject);
        appendJSONAttribute(out, CM_CREATOR, dcCreator);
        //appendJSONAttribute(out, CM_MODIFIED, RFC3339Format.format(dcModified));
        out.append("}");
        out.flush();
    }
    private void appendJSONAttribute(Writer out, String key, String value) throws IOException {
        out.append("\t\""+key+"\": \""+value+"\",\n");
        
    }
    String getChildContent(Element element, String tagName) {
        NodeList list = element.getElementsByTagName(tagName);
        if (list.getLength() == 0) return null;
        Element child = (Element) list.item(0);
        return child.getTextContent();
    }
    public String getDcCreator() {
        return dcCreator;
    }
    public String getDcDescription() {
        return dcDescription;
    }
    public String getDcIdentifier() {
        return dcIdentifier;
    }
    public Date getDcModified() {
        return dcModified;
    }
    public String getDcSubject() {
        return dcSubject;
    }
    public String getDcTitle() {
        return dcTitle;
    }
    public String getDcType() {
        return dcType;
    }
    public String getUri() {
        return uri;
    }
    public void setDcCreator(String dcCreator) {
        this.dcCreator = dcCreator;
    }
    public void setDcDescription(String dcDescription) {
        this.dcDescription = dcDescription;
    }
    public void setDcSubject(String dcSubject) {
        this.dcSubject = dcSubject;
    }
    public void setDcTitle(String dcTitle) {
        this.dcTitle = dcTitle;
    }
    public void setDcType(String dcType) {
        this.dcType = dcType;
    }
    public void setUri(String uri) {
        this.uri = uri;
    }
}

0 votes



One answer

Permanent link
 Hi helene,
is there any context for these codes?
out.append("\t<"+id+">"+value+"\n");  this seems doesn't have the end tag.

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,951

Question asked: May 28 '13, 2:48 a.m.

Question was seen: 5,202 times

Last updated: May 28 '13, 4:43 a.m.

Confirmation Cancel Confirm