[mhk] r1091 committed - Person ocurrence and function added on WebSources@mhk_families

1 view
Skip to first unread message

codesite...@google.com

unread,
Jun 30, 2013, 4:05:53 PM6/30/13
to mhk-dis...@googlegroups.com
Revision: 1091
Author: tbc...@gmail.com
Date: Sun Jun 30 13:05:42 2013
Log: Person ocurrence and function added on WebSources@mhk_families
http://code.google.com/p/mhk/source/detail?r=1091

Modified:
/branches/mhk_families/idb/etc/template/new/create_source.vm
/branches/mhk_families/idb/etc/template/new/edit_files.vm
/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/parser/SaveWebSource.java
/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/servlet/SaveSource.java

=======================================
--- /branches/mhk_families/idb/etc/template/new/create_source.vm Sun Jun 30
08:22:55 2013
+++ /branches/mhk_families/idb/etc/template/new/create_source.vm Sun Jun 30
13:05:42 2013
@@ -17,6 +17,8 @@
var acts=new Array();
var functions=new Array();

+ var xmlhttp;
+
function refreshSelects(){
##actualizar selects
document.getElementById("attribute_select").options.length = 0;
@@ -435,6 +437,10 @@
button.innerHTML="<input type='button' value='Remove Function'
onClick='removeFunc(this)'>";
count_functions++;
}
+
+ function responseFunction(){
+ alert(xmlhttp.responseText);
+ }

function submitForm() {

@@ -449,6 +455,7 @@

var jsonDataObject = new Object();
jsonDataObject.source = source;
+ jsonDataObject.sourceName = source.name;
jsonDataObject.persons = persons;
jsonDataObject.attributes = attributes;
jsonDataObject.relations = relations;
@@ -457,7 +464,7 @@

##turn the jsonData object into a string so it can be passed to the
servlet
var jsonData = JSON.stringify(jsonDataObject);
- var xmlhttp;
+

if (window.XMLHttpRequest){
## code for IE7+, Firefox, Chrome, Opera, Safari
@@ -467,10 +474,10 @@
## code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
-

xmlhttp.open("POST","${uri}?dbname=$!dbname&action=save_source&script=create_source.vm",true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send('json='+encodeURIComponent(jsonData));
+ alert("Import started!");
}
</script>

@@ -567,7 +574,7 @@

<br></br>

- <input type="button" value="Save Web Source" onclick="submitForm()">
+ <input type="button" value="Import Web Source" onclick="submitForm()">
</div>

#parse("new/footer.vm")
=======================================
--- /branches/mhk_families/idb/etc/template/new/edit_files.vm Sun Jun 23
07:08:10 2013
+++ /branches/mhk_families/idb/etc/template/new/edit_files.vm Sun Jun 30
13:05:42 2013
@@ -86,6 +86,7 @@
}

xmlhttp.open("GET","${uri}?dbname=$db.dbname&action=save_file&script=show_sources.vm&currentdir=$currentdir&extension=$extension&filename="+filename+"&file_content="+final_content,true);
xmlhttp.send();
+ alert("File Saved!");
}
</script>

=======================================
---
/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/parser/SaveWebSource.java
Sun Jun 30 09:01:08 2013
+++
/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/parser/SaveWebSource.java
Sun Jun 30 13:05:42 2013
@@ -11,16 +11,18 @@
import org.jdom2.output.XMLOutputter;
import java.io.FileWriter;
import java.io.IOException;
+import java.util.HashMap;

public class SaveWebSource {
private Element root;
private int count_attributes;
- //private int count_person_ocur;
+ private int count_person_ocurr;
private int count_relations;
private int count_individuals;
private int count_events;
private String filename;
- String sourceId;
+ private String sourceId;
+ private HashMap <String,String> persons;

public SaveWebSource() {}

@@ -29,7 +31,9 @@
count_relations=1;
count_individuals=1;
count_events=1;
- //count_person_ocur=1;
+ count_person_ocurr=1;
+
+ persons=new HashMap <String,String>();

//XML root
root = new Element("KLEIO");
@@ -58,11 +62,13 @@
Document doc = new Document(root);
XMLOutputter xmlOutput = new XMLOutputter();

- // display nice nice
+ // display nice
xmlOutput.setFormat(Format.getPrettyFormat());
try {
xmlOutput.output(doc, new FileWriter(path+"\\"+this.filename+".xml"));
- FileWriter kleioFile = new FileWriter(path+"\\"+this.filename+".cli");
+// xmlOutput.output(doc, new FileWriter(path+"\\"+this.filename+".cli"));
+// FileWriter kleioFile = new FileWriter(path+"\\"+this.filename+".err");
+// kleioFile = new FileWriter(path+"\\"+this.filename+".rpt");
//System.out.println("FILE SAVED!");
} catch (IOException e) {
// TODO Auto-generated catch block
@@ -251,6 +257,140 @@

root.addContent(attribute);

+ count_relations++;
+
+ //CREATE PERSON OCURRENCE
+ attribute=new Element("GROUP");
+ String
ocurrenceId="WEBSOURCE-"+this.filename+"-person_oc-"+count_person_ocurr;
+ attribute.setAttribute("ID",ocurrenceId);
+ attribute.setAttribute("NAME","act");
+ attribute.setAttribute("CLASS","person");
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","id");
+ s.setAttribute("CLASS","id");
+ core=new Element("core");
+ core.addContent(ocurrenceId);
+ s.addContent(core);
+ attribute.addContent(s);
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","groupname");
+ s.setAttribute("CLASS","groupname");
+ core=new Element("core");
+ core.addContent("act");
+ s.addContent(core);
+ attribute.addContent(s);
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","inside");
+ s.setAttribute("CLASS","inside");
+ core=new Element("core");
+ core.addContent(actId);
+ s.addContent(core);
+ attribute.addContent(s);
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","class");
+ s.setAttribute("CLASS","class");
+ core=new Element("core");
+ core.addContent("person");
+ s.addContent(core);
+ attribute.addContent(s);
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","nome");
+ s.setAttribute("CLASS","name");
+ core=new Element("core");
+ core.addContent(persons.get(individualId));
+ s.addContent(core);
+ attribute.addContent(s);
+
+ root.addContent(attribute);
+
+ count_person_ocurr++;
+
+ //PUT RELATION GROUP OF FUNCTION-IN-EVENT FOR OCURRENCE
+ attribute=new Element("GROUP");
+ relationId="WEBSOURCE-"+this.filename+"-relation-"+count_relations;
+ attribute.setAttribute("ID",relationId);
+ attribute.setAttribute("NAME","relation");
+ attribute.setAttribute("CLASS","relation");
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","groupname");
+ s.setAttribute("CLASS","groupname");
+ core=new Element("core");
+ core.addContent("relation");
+ s.addContent(core);
+ attribute.addContent(s);
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","inside");
+ s.setAttribute("CLASS","inside");
+ core=new Element("core");
+ core.addContent(ocurrenceId);
+ s.addContent(core);
+ attribute.addContent(s);
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","class");
+ s.setAttribute("CLASS","class");
+ core=new Element("core");
+ core.addContent("relation");
+ s.addContent(core);
+ attribute.addContent(s);
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","tipo");
+ s.setAttribute("CLASS","type");
+ core=new Element("core");
+ core.addContent("function-in-act");
+ s.addContent(core);
+ attribute.addContent(s);
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","destname");
+ s.setAttribute("CLASS","destname");
+ core=new Element("core");
+ core.addContent("act");
+ s.addContent(core);
+ attribute.addContent(s);
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","origin");
+ s.setAttribute("CLASS","origin");
+ core=new Element("core");
+ core.addContent(ocurrenceId);
+ s.addContent(core);
+ attribute.addContent(s);
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","destination");
+ s.setAttribute("CLASS","destination");
+ core=new Element("core");
+ core.addContent(actId);
+ s.addContent(core);
+ attribute.addContent(s);
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","id");
+ s.setAttribute("CLASS","id");
+ core=new Element("core");
+ core.addContent(relationId);
+ s.addContent(core);
+ attribute.addContent(s);
+
+ s=new Element("ELEMENT");
+ s.setAttribute("NAME","value");
+ s.setAttribute("CLASS","value");
+ core=new Element("core");
+ core.addContent((String)function.get("value"));
+ s.addContent(core);
+ attribute.addContent(s);
+
+ root.addContent(attribute);
+
count_relations++;
}
}
@@ -330,6 +470,9 @@
for (int i=0;i<individuals.size();i++){
JSONObject person = (JSONObject)individuals.get(i);
String
individualId="WEBSOURCE-"+this.filename+"-person-"+count_individuals;
+ String name=(String)person.get("name");
+ persons.put(individualId,name);
+
Element individual=new Element("GROUP");
Element s,core;
individual.setAttribute("ID",individualId);
@@ -373,7 +516,7 @@
s.setAttribute("NAME","nome");
s.setAttribute("CLASS","name");
core=new Element("core");
- core.addContent((String)person.get("name"));
+ core.addContent(name);
s.addContent(core);
individual.addContent(s);

=======================================
--- /branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/servlet/SaveSource.java
Fri Jun 28 15:36:49 2013
+++ /branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/servlet/SaveSource.java
Sun Jun 30 13:05:42 2013
@@ -7,10 +7,13 @@
*/
import org.apache.velocity.context.Context;
import pt.uc.cisuc.jrc.mhk.rch.DBSystem;
-import pt.uc.cisuc.jrc.mhk.parser.SaveWebSource;
+import pt.uc.cisuc.jrc.mhk.parser.*;
+import pt.uc.cisuc.jrc.mhk.thread.*;

import org.json.simple.*;
import java.io.File;
+import java.io.PrintWriter;
+import java.io.IOException;


import java.util.Vector;
@@ -22,7 +25,7 @@

public class SaveSource extends Command {
/** Name of the Template */
- public static final String SOURCE = "create_source.vm";
+ public static final String SOURCE = "importer_output.vm";

public SaveSource(ServletContext con, HttpServletRequest req,
HttpServletResponse resp) {
super(con, req, resp);
@@ -63,7 +66,47 @@
SaveWebSource ws=new SaveWebSource();
ws.start(currentdir,jsonData);

-
ctx.put("bgthread",request.getSession().getAttribute("background.thread"));
+ String source_name = (String) jsonData.get("sourceName");
+
+ String filename=currentdir+"\\"+source_name+".xml";
+
+ BackgroundThread bg = (BackgroundThread)
request.getSession().getAttribute("background.thread");
+ if (bg == null) {
+ bg = new BackgroundThread();
+ bg.start();
+ request.getSession().setAttribute("background.thread", bg);
+ }
+
+ KleioImporter importer = (KleioImporter)
session.getAttribute("kleio.importer");
+ DBSystem db = (DBSystem) session.getAttribute("mhk.dbsystem.bg");
+ if (db == null) {
+ ctx.put("error", "[DoSaveSource]INTERNAL ERROR no DBSystem in
session scope.");
+ context.log("[DoSaveSource]INTERNAL ERROR no DBSystem in
session scope.");
+ return "error_page.vm";
+ }
+
+ if (importer == null) {
+ System.out.println("No importer obect in session scope.
Creating one");
+ importer = new KleioImporter(db,bg);
+ session.setAttribute("kleio.importer", importer);
+
+ } else
+ importer.setDB(db);
+
+// String replaceLevel = request.getParameter("replace");
+// int replaceCode = DBSystem.SOURCE_REPLACE;//2 substitui 1 importa
+
+// boolean checkFlag = false;
+
+ System.out.println("[DoSaveSource] scheduling file " + filename
+ " for import.");
+ importer.backgroundImport(filename, false, 2);
+ ctx.put("start", "yes");
+ ctx.put("filename", filename);
+ ctx.put("currentdir", currentdir);
+
+
+ ctx.put("bgthread",bg);
+
return SOURCE;
}
}
Reply all
Reply to author
Forward
0 new messages