Java tutorial
// ============================================================================ // // Copyright (c) 2006-2013, Talend Inc. // // This source code has been automatically generated by_Talend Open Studio for Data Integration // / Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package bio2rdf.datahub_get_stats_0_1; import routines.Mathematical; import routines.DataOperation; import routines.BioUtil; import routines.Relational; import routines.TalendDate; import routines.TalendDataGenerator; import routines.Numeric; import routines.MD5; import routines.TalendString; import routines.StringHandling; import routines.system.*; import routines.system.api.*; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.math.BigDecimal; import java.io.ByteArrayOutputStream; import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.io.IOException; import java.util.Comparator; //the import part of tJavaRow_2 //import java.util.List; @SuppressWarnings("unused") /** * Job: datahub_get_stats Purpose: <br> * Description: <br> * @author test@talend.com * @version 5.5.0.r117820 * @status */ public class datahub_get_stats implements TalendJob { public final Object obj = new Object(); // for transmiting parameters purpose private Object valueObject = null; public Object getValueObject() { return this.valueObject; } public void setValueObject(Object valueObject) { this.valueObject = valueObject; } private final static String defaultCharset = java.nio.charset.Charset.defaultCharset().name(); private final static String utf8Charset = "UTF-8"; // create and load default properties private java.util.Properties defaultProps = new java.util.Properties(); // create application properties with default public class ContextProperties extends java.util.Properties { private static final long serialVersionUID = 1L; public ContextProperties(java.util.Properties properties) { super(properties); } public ContextProperties() { super(); } public void synchronizeContext() { if (inputFile != null) { this.setProperty("inputFile", inputFile.toString()); } if (endpoint_namespace != null) { this.setProperty("endpoint_namespace", endpoint_namespace.toString()); } } public String inputFile; public String getInputFile() { return this.inputFile; } public String endpoint_namespace; public String getEndpoint_namespace() { return this.endpoint_namespace; } } private ContextProperties context = new ContextProperties(); public ContextProperties getContext() { return this.context; } private final String jobVersion = "0.1"; private final String jobName = "datahub_get_stats"; private final String projectName = "BIO2RDF"; public Integer errorCode = null; private String currentComponent = ""; private final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>(); private final java.util.Map<String, Long> start_Hash = new java.util.HashMap<String, Long>(); private final java.util.Map<String, Long> end_Hash = new java.util.HashMap<String, Long>(); private final java.util.Map<String, Boolean> ok_Hash = new java.util.HashMap<String, Boolean>(); public final java.util.List<String[]> globalBuffer = new java.util.ArrayList<String[]>(); public boolean isExportedAsOSGI = false; // OSGi DataSource private final static String KEY_DB_DATASOURCES = "KEY_DB_DATASOURCES"; public void setDataSources(java.util.Map<String, javax.sql.DataSource> dataSources) { java.util.Map<String, routines.system.TalendDataSource> talendDataSources = new java.util.HashMap<String, routines.system.TalendDataSource>(); for (java.util.Map.Entry<String, javax.sql.DataSource> dataSourceEntry : dataSources.entrySet()) { talendDataSources.put(dataSourceEntry.getKey(), new routines.system.TalendDataSource(dataSourceEntry.getValue())); } globalMap.put(KEY_DB_DATASOURCES, talendDataSources); } private final java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); private final java.io.PrintStream errorMessagePS = new java.io.PrintStream( new java.io.BufferedOutputStream(baos)); public String getExceptionStackTrace() { if ("failure".equals(this.getStatus())) { errorMessagePS.flush(); return baos.toString(); } return null; } private java.lang.Exception exception = null; public java.lang.Exception getException() { if ("failure".equals(this.getStatus())) { return this.exception; } return null; } private class TalendException extends java.lang.Exception { private static final long serialVersionUID = 1L; private java.util.Map<String, Object> globalMap = null; private java.lang.Exception e = null; private String currentComponent = null; private String virtualComponentName = null; public void setVirtualComponentName(String virtualComponentName) { this.virtualComponentName = virtualComponentName; } private TalendException(java.lang.Exception e, String errorComponent, final java.util.Map<String, Object> globalMap) { this.currentComponent = errorComponent; this.globalMap = globalMap; this.e = e; } public java.lang.Exception getException() { return this.e; } public String getCurrentComponent() { return this.currentComponent; } public String getExceptionCauseMessage(java.lang.Exception e) { Throwable cause = e; String message = null; int i = 10; while (null != cause && 0 < i--) { message = cause.getMessage(); if (null == message) { cause = cause.getCause(); } else { break; } } if (null == message) { message = e.getClass().getName(); } return message; } @Override public void printStackTrace() { if (!(e instanceof TalendException || e instanceof TDieException)) { if (virtualComponentName != null && currentComponent.indexOf(virtualComponentName + "_") == 0) { globalMap.put(virtualComponentName + "_ERROR_MESSAGE", getExceptionCauseMessage(e)); } globalMap.put(currentComponent + "_ERROR_MESSAGE", getExceptionCauseMessage(e)); System.err.println("Exception in component " + currentComponent); } if (!(e instanceof TDieException)) { if (e instanceof TalendException) { e.printStackTrace(); } else { e.printStackTrace(); e.printStackTrace(errorMessagePS); datahub_get_stats.this.exception = e; } } if (!(e instanceof TalendException)) { try { for (java.lang.reflect.Method m : this.getClass().getEnclosingClass().getMethods()) { if (m.getName().compareTo(currentComponent + "_error") == 0) { m.invoke(datahub_get_stats.this, new Object[] { e, currentComponent, globalMap }); break; } } if (!(e instanceof TDieException)) { } } catch (java.lang.SecurityException e) { this.e.printStackTrace(); } catch (java.lang.IllegalArgumentException e) { this.e.printStackTrace(); } catch (java.lang.IllegalAccessException e) { this.e.printStackTrace(); } catch (java.lang.reflect.InvocationTargetException e) { this.e.printStackTrace(); } } } } public void tHttpRequest_1_error(java.lang.Exception exception, String errorComponent, final java.util.Map<String, Object> globalMap) throws TalendException { end_Hash.put(errorComponent, System.currentTimeMillis()); status = "failure"; tHttpRequest_1_onSubJobError(exception, errorComponent, globalMap); } public void tExtractJSONFields_1_error(java.lang.Exception exception, String errorComponent, final java.util.Map<String, Object> globalMap) throws TalendException { end_Hash.put(errorComponent, System.currentTimeMillis()); status = "failure"; tHttpRequest_1_onSubJobError(exception, errorComponent, globalMap); } public void tExtractRegexFields_1_error(java.lang.Exception exception, String errorComponent, final java.util.Map<String, Object> globalMap) throws TalendException { end_Hash.put(errorComponent, System.currentTimeMillis()); status = "failure"; tHttpRequest_1_onSubJobError(exception, errorComponent, globalMap); } public void tJavaRow_2_error(java.lang.Exception exception, String errorComponent, final java.util.Map<String, Object> globalMap) throws TalendException { end_Hash.put(errorComponent, System.currentTimeMillis()); status = "failure"; tHttpRequest_1_onSubJobError(exception, errorComponent, globalMap); } public void tFilterRow_1_error(java.lang.Exception exception, String errorComponent, final java.util.Map<String, Object> globalMap) throws TalendException { end_Hash.put(errorComponent, System.currentTimeMillis()); status = "failure"; tHttpRequest_1_onSubJobError(exception, errorComponent, globalMap); } public void tLogRow_2_error(java.lang.Exception exception, String errorComponent, final java.util.Map<String, Object> globalMap) throws TalendException { end_Hash.put(errorComponent, System.currentTimeMillis()); status = "failure"; tHttpRequest_1_onSubJobError(exception, errorComponent, globalMap); } public void tBufferOutput_1_error(java.lang.Exception exception, String errorComponent, final java.util.Map<String, Object> globalMap) throws TalendException { end_Hash.put(errorComponent, System.currentTimeMillis()); status = "failure"; tHttpRequest_1_onSubJobError(exception, errorComponent, globalMap); } public void tHttpRequest_1_onSubJobError(java.lang.Exception exception, String errorComponent, final java.util.Map<String, Object> globalMap) throws TalendException { resumeUtil.addLog("SYSTEM_LOG", "NODE:" + errorComponent, "", Thread.currentThread().getId() + "", "FATAL", "", exception.getMessage(), ResumeUtil.getExceptionStackTrace(exception), ""); } public static class row5Struct implements routines.system.IPersistableRow<row5Struct> { final static byte[] commonByteArrayLock_BIO2RDF_datahub_get_stats = new byte[0]; static byte[] commonByteArray_BIO2RDF_datahub_get_stats = new byte[0]; public String link; public String getLink() { return this.link; } public String stat; public String getStat() { return this.stat; } private String readString(ObjectInputStream dis) throws IOException { String strReturn = null; int length = 0; length = dis.readInt(); if (length == -1) { strReturn = null; } else { if (length > commonByteArray_BIO2RDF_datahub_get_stats.length) { if (length < 1024 && commonByteArray_BIO2RDF_datahub_get_stats.length == 0) { commonByteArray_BIO2RDF_datahub_get_stats = new byte[1024]; } else { commonByteArray_BIO2RDF_datahub_get_stats = new byte[2 * length]; } } dis.readFully(commonByteArray_BIO2RDF_datahub_get_stats, 0, length); strReturn = new String(commonByteArray_BIO2RDF_datahub_get_stats, 0, length, utf8Charset); } return strReturn; } private void writeString(String str, ObjectOutputStream dos) throws IOException { if (str == null) { dos.writeInt(-1); } else { byte[] byteArray = str.getBytes(utf8Charset); dos.writeInt(byteArray.length); dos.write(byteArray); } } public void readData(ObjectInputStream dis) { synchronized (commonByteArrayLock_BIO2RDF_datahub_get_stats) { try { int length = 0; this.link = readString(dis); this.stat = readString(dis); } catch (IOException e) { throw new RuntimeException(e); } } } public void writeData(ObjectOutputStream dos) { try { // String writeString(this.link, dos); // String writeString(this.stat, dos); } catch (IOException e) { throw new RuntimeException(e); } } public String toString() { StringBuilder sb = new StringBuilder(); sb.append(super.toString()); sb.append("["); sb.append("link=" + link); sb.append(",stat=" + stat); sb.append("]"); return sb.toString(); } /** * Compare keys */ public int compareTo(row5Struct other) { int returnValue = -1; return returnValue; } private int checkNullsAndCompare(Object object1, Object object2) { int returnValue = 0; if (object1 instanceof Comparable && object2 instanceof Comparable) { returnValue = ((Comparable) object1).compareTo(object2); } else if (object1 != null && object2 != null) { returnValue = compareStrings(object1.toString(), object2.toString()); } else if (object1 == null && object2 != null) { returnValue = 1; } else if (object1 != null && object2 == null) { returnValue = -1; } else { returnValue = 0; } return returnValue; } private int compareStrings(String string1, String string2) { return string1.compareTo(string2); } } public static class row10Struct implements routines.system.IPersistableRow<row10Struct> { final static byte[] commonByteArrayLock_BIO2RDF_datahub_get_stats = new byte[0]; static byte[] commonByteArray_BIO2RDF_datahub_get_stats = new byte[0]; public String link; public String getLink() { return this.link; } public String stat; public String getStat() { return this.stat; } private String readString(ObjectInputStream dis) throws IOException { String strReturn = null; int length = 0; length = dis.readInt(); if (length == -1) { strReturn = null; } else { if (length > commonByteArray_BIO2RDF_datahub_get_stats.length) { if (length < 1024 && commonByteArray_BIO2RDF_datahub_get_stats.length == 0) { commonByteArray_BIO2RDF_datahub_get_stats = new byte[1024]; } else { commonByteArray_BIO2RDF_datahub_get_stats = new byte[2 * length]; } } dis.readFully(commonByteArray_BIO2RDF_datahub_get_stats, 0, length); strReturn = new String(commonByteArray_BIO2RDF_datahub_get_stats, 0, length, utf8Charset); } return strReturn; } private void writeString(String str, ObjectOutputStream dos) throws IOException { if (str == null) { dos.writeInt(-1); } else { byte[] byteArray = str.getBytes(utf8Charset); dos.writeInt(byteArray.length); dos.write(byteArray); } } public void readData(ObjectInputStream dis) { synchronized (commonByteArrayLock_BIO2RDF_datahub_get_stats) { try { int length = 0; this.link = readString(dis); this.stat = readString(dis); } catch (IOException e) { throw new RuntimeException(e); } } } public void writeData(ObjectOutputStream dos) { try { // String writeString(this.link, dos); // String writeString(this.stat, dos); } catch (IOException e) { throw new RuntimeException(e); } } public String toString() { StringBuilder sb = new StringBuilder(); sb.append(super.toString()); sb.append("["); sb.append("link=" + link); sb.append(",stat=" + stat); sb.append("]"); return sb.toString(); } /** * Compare keys */ public int compareTo(row10Struct other) { int returnValue = -1; return returnValue; } private int checkNullsAndCompare(Object object1, Object object2) { int returnValue = 0; if (object1 instanceof Comparable && object2 instanceof Comparable) { returnValue = ((Comparable) object1).compareTo(object2); } else if (object1 != null && object2 != null) { returnValue = compareStrings(object1.toString(), object2.toString()); } else if (object1 == null && object2 != null) { returnValue = 1; } else if (object1 != null && object2 == null) { returnValue = -1; } else { returnValue = 0; } return returnValue; } private int compareStrings(String string1, String string2) { return string1.compareTo(string2); } } public static class row9Struct implements routines.system.IPersistableRow<row9Struct> { final static byte[] commonByteArrayLock_BIO2RDF_datahub_get_stats = new byte[0]; static byte[] commonByteArray_BIO2RDF_datahub_get_stats = new byte[0]; public String link; public String getLink() { return this.link; } public String stat; public String getStat() { return this.stat; } private String readString(ObjectInputStream dis) throws IOException { String strReturn = null; int length = 0; length = dis.readInt(); if (length == -1) { strReturn = null; } else { if (length > commonByteArray_BIO2RDF_datahub_get_stats.length) { if (length < 1024 && commonByteArray_BIO2RDF_datahub_get_stats.length == 0) { commonByteArray_BIO2RDF_datahub_get_stats = new byte[1024]; } else { commonByteArray_BIO2RDF_datahub_get_stats = new byte[2 * length]; } } dis.readFully(commonByteArray_BIO2RDF_datahub_get_stats, 0, length); strReturn = new String(commonByteArray_BIO2RDF_datahub_get_stats, 0, length, utf8Charset); } return strReturn; } private void writeString(String str, ObjectOutputStream dos) throws IOException { if (str == null) { dos.writeInt(-1); } else { byte[] byteArray = str.getBytes(utf8Charset); dos.writeInt(byteArray.length); dos.write(byteArray); } } public void readData(ObjectInputStream dis) { synchronized (commonByteArrayLock_BIO2RDF_datahub_get_stats) { try { int length = 0; this.link = readString(dis); this.stat = readString(dis); } catch (IOException e) { throw new RuntimeException(e); } } } public void writeData(ObjectOutputStream dos) { try { // String writeString(this.link, dos); // String writeString(this.stat, dos); } catch (IOException e) { throw new RuntimeException(e); } } public String toString() { StringBuilder sb = new StringBuilder(); sb.append(super.toString()); sb.append("["); sb.append("link=" + link); sb.append(",stat=" + stat); sb.append("]"); return sb.toString(); } /** * Compare keys */ public int compareTo(row9Struct other) { int returnValue = -1; return returnValue; } private int checkNullsAndCompare(Object object1, Object object2) { int returnValue = 0; if (object1 instanceof Comparable && object2 instanceof Comparable) { returnValue = ((Comparable) object1).compareTo(object2); } else if (object1 != null && object2 != null) { returnValue = compareStrings(object1.toString(), object2.toString()); } else if (object1 == null && object2 != null) { returnValue = 1; } else if (object1 != null && object2 == null) { returnValue = -1; } else { returnValue = 0; } return returnValue; } private int compareStrings(String string1, String string2) { return string1.compareTo(string2); } } public static class row8Struct implements routines.system.IPersistableRow<row8Struct> { final static byte[] commonByteArrayLock_BIO2RDF_datahub_get_stats = new byte[0]; static byte[] commonByteArray_BIO2RDF_datahub_get_stats = new byte[0]; public String count; public String getCount() { return this.count; } public String linkNamespace; public String getLinkNamespace() { return this.linkNamespace; } private String readString(ObjectInputStream dis) throws IOException { String strReturn = null; int length = 0; length = dis.readInt(); if (length == -1) { strReturn = null; } else { if (length > commonByteArray_BIO2RDF_datahub_get_stats.length) { if (length < 1024 && commonByteArray_BIO2RDF_datahub_get_stats.length == 0) { commonByteArray_BIO2RDF_datahub_get_stats = new byte[1024]; } else { commonByteArray_BIO2RDF_datahub_get_stats = new byte[2 * length]; } } dis.readFully(commonByteArray_BIO2RDF_datahub_get_stats, 0, length); strReturn = new String(commonByteArray_BIO2RDF_datahub_get_stats, 0, length, utf8Charset); } return strReturn; } private void writeString(String str, ObjectOutputStream dos) throws IOException { if (str == null) { dos.writeInt(-1); } else { byte[] byteArray = str.getBytes(utf8Charset); dos.writeInt(byteArray.length); dos.write(byteArray); } } public void readData(ObjectInputStream dis) { synchronized (commonByteArrayLock_BIO2RDF_datahub_get_stats) { try { int length = 0; this.count = readString(dis); this.linkNamespace = readString(dis); } catch (IOException e) { throw new RuntimeException(e); } } } public void writeData(ObjectOutputStream dos) { try { // String writeString(this.count, dos); // String writeString(this.linkNamespace, dos); } catch (IOException e) { throw new RuntimeException(e); } } public String toString() { StringBuilder sb = new StringBuilder(); sb.append(super.toString()); sb.append("["); sb.append("count=" + count); sb.append(",linkNamespace=" + linkNamespace); sb.append("]"); return sb.toString(); } /** * Compare keys */ public int compareTo(row8Struct other) { int returnValue = -1; return returnValue; } private int checkNullsAndCompare(Object object1, Object object2) { int returnValue = 0; if (object1 instanceof Comparable && object2 instanceof Comparable) { returnValue = ((Comparable) object1).compareTo(object2); } else if (object1 != null && object2 != null) { returnValue = compareStrings(object1.toString(), object2.toString()); } else if (object1 == null && object2 != null) { returnValue = 1; } else if (object1 != null && object2 == null) { returnValue = -1; } else { returnValue = 0; } return returnValue; } private int compareStrings(String string1, String string2) { return string1.compareTo(string2); } } public static class row7Struct implements routines.system.IPersistableRow<row7Struct> { final static byte[] commonByteArrayLock_BIO2RDF_datahub_get_stats = new byte[0]; static byte[] commonByteArray_BIO2RDF_datahub_get_stats = new byte[0]; public String link; public String getLink() { return this.link; } public String count; public String getCount() { return this.count; } private String readString(ObjectInputStream dis) throws IOException { String strReturn = null; int length = 0; length = dis.readInt(); if (length == -1) { strReturn = null; } else { if (length > commonByteArray_BIO2RDF_datahub_get_stats.length) { if (length < 1024 && commonByteArray_BIO2RDF_datahub_get_stats.length == 0) { commonByteArray_BIO2RDF_datahub_get_stats = new byte[1024]; } else { commonByteArray_BIO2RDF_datahub_get_stats = new byte[2 * length]; } } dis.readFully(commonByteArray_BIO2RDF_datahub_get_stats, 0, length); strReturn = new String(commonByteArray_BIO2RDF_datahub_get_stats, 0, length, utf8Charset); } return strReturn; } private void writeString(String str, ObjectOutputStream dos) throws IOException { if (str == null) { dos.writeInt(-1); } else { byte[] byteArray = str.getBytes(utf8Charset); dos.writeInt(byteArray.length); dos.write(byteArray); } } public void readData(ObjectInputStream dis) { synchronized (commonByteArrayLock_BIO2RDF_datahub_get_stats) { try { int length = 0; this.link = readString(dis); this.count = readString(dis); } catch (IOException e) { throw new RuntimeException(e); } } } public void writeData(ObjectOutputStream dos) { try { // String writeString(this.link, dos); // String writeString(this.count, dos); } catch (IOException e) { throw new RuntimeException(e); } } public String toString() { StringBuilder sb = new StringBuilder(); sb.append(super.toString()); sb.append("["); sb.append("link=" + link); sb.append(",count=" + count); sb.append("]"); return sb.toString(); } /** * Compare keys */ public int compareTo(row7Struct other) { int returnValue = -1; return returnValue; } private int checkNullsAndCompare(Object object1, Object object2) { int returnValue = 0; if (object1 instanceof Comparable && object2 instanceof Comparable) { returnValue = ((Comparable) object1).compareTo(object2); } else if (object1 != null && object2 != null) { returnValue = compareStrings(object1.toString(), object2.toString()); } else if (object1 == null && object2 != null) { returnValue = 1; } else if (object1 != null && object2 == null) { returnValue = -1; } else { returnValue = 0; } return returnValue; } private int compareStrings(String string1, String string2) { return string1.compareTo(string2); } } public static class row6Struct implements routines.system.IPersistableRow<row6Struct> { final static byte[] commonByteArrayLock_BIO2RDF_datahub_get_stats = new byte[0]; static byte[] commonByteArray_BIO2RDF_datahub_get_stats = new byte[0]; public String ResponseContent; public String getResponseContent() { return this.ResponseContent; } private String readString(ObjectInputStream dis) throws IOException { String strReturn = null; int length = 0; length = dis.readInt(); if (length == -1) { strReturn = null; } else { if (length > commonByteArray_BIO2RDF_datahub_get_stats.length) { if (length < 1024 && commonByteArray_BIO2RDF_datahub_get_stats.length == 0) { commonByteArray_BIO2RDF_datahub_get_stats = new byte[1024]; } else { commonByteArray_BIO2RDF_datahub_get_stats = new byte[2 * length]; } } dis.readFully(commonByteArray_BIO2RDF_datahub_get_stats, 0, length); strReturn = new String(commonByteArray_BIO2RDF_datahub_get_stats, 0, length, utf8Charset); } return strReturn; } private void writeString(String str, ObjectOutputStream dos) throws IOException { if (str == null) { dos.writeInt(-1); } else { byte[] byteArray = str.getBytes(utf8Charset); dos.writeInt(byteArray.length); dos.write(byteArray); } } public void readData(ObjectInputStream dis) { synchronized (commonByteArrayLock_BIO2RDF_datahub_get_stats) { try { int length = 0; this.ResponseContent = readString(dis); } catch (IOException e) { throw new RuntimeException(e); } } } public void writeData(ObjectOutputStream dos) { try { // String writeString(this.ResponseContent, dos); } catch (IOException e) { throw new RuntimeException(e); } } public String toString() { StringBuilder sb = new StringBuilder(); sb.append(super.toString()); sb.append("["); sb.append("ResponseContent=" + ResponseContent); sb.append("]"); return sb.toString(); } /** * Compare keys */ public int compareTo(row6Struct other) { int returnValue = -1; return returnValue; } private int checkNullsAndCompare(Object object1, Object object2) { int returnValue = 0; if (object1 instanceof Comparable && object2 instanceof Comparable) { returnValue = ((Comparable) object1).compareTo(object2); } else if (object1 != null && object2 != null) { returnValue = compareStrings(object1.toString(), object2.toString()); } else if (object1 == null && object2 != null) { returnValue = 1; } else if (object1 != null && object2 == null) { returnValue = -1; } else { returnValue = 0; } return returnValue; } private int compareStrings(String string1, String string2) { return string1.compareTo(string2); } } public void tHttpRequest_1Process(final java.util.Map<String, Object> globalMap) throws TalendException { globalMap.put("tHttpRequest_1_SUBPROCESS_STATE", 0); final boolean execStat = this.execStat; String iterateId = ""; int iterateLoop = 0; String currentComponent = ""; java.util.Map<String, Object> resourceMap = new java.util.HashMap<String, Object>(); try { String currentMethodName = new java.lang.Exception().getStackTrace()[0].getMethodName(); boolean resumeIt = currentMethodName.equals(resumeEntryMethodName); if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start // the // resume globalResumeTicket = true; row6Struct row6 = new row6Struct(); row7Struct row7 = new row7Struct(); row8Struct row8 = new row8Struct(); row9Struct row9 = new row9Struct(); row10Struct row10 = new row10Struct(); row10Struct row5 = row10; /** * [tBufferOutput_1 begin ] start */ ok_Hash.put("tBufferOutput_1", false); start_Hash.put("tBufferOutput_1", System.currentTimeMillis()); currentComponent = "tBufferOutput_1"; int tos_count_tBufferOutput_1 = 0; /** * [tBufferOutput_1 begin ] stop */ /** * [tLogRow_2 begin ] start */ ok_Hash.put("tLogRow_2", false); start_Hash.put("tLogRow_2", System.currentTimeMillis()); currentComponent = "tLogRow_2"; int tos_count_tLogRow_2 = 0; /** * [tLogRow_2 begin ] stop */ /** * [tFilterRow_1 begin ] start */ ok_Hash.put("tFilterRow_1", false); start_Hash.put("tFilterRow_1", System.currentTimeMillis()); currentComponent = "tFilterRow_1"; int tos_count_tFilterRow_1 = 0; int nb_line_tFilterRow_1 = 0; int nb_line_ok_tFilterRow_1 = 0; int nb_line_reject_tFilterRow_1 = 0; class Operator_tFilterRow_1 { private String sErrorMsg = ""; private boolean bMatchFlag = true; private String sUnionFlag = "&&"; public Operator_tFilterRow_1(String unionFlag) { sUnionFlag = unionFlag; bMatchFlag = "||".equals(unionFlag) ? false : true; } public String getErrorMsg() { if (sErrorMsg != null && sErrorMsg.length() > 1) return sErrorMsg.substring(1); else return null; } public boolean getMatchFlag() { return bMatchFlag; } public void matches(boolean partMatched, String reason) { // no need to care about the next judgement if ("||".equals(sUnionFlag) && bMatchFlag) { return; } if (!partMatched) { sErrorMsg += "|" + reason; } if ("||".equals(sUnionFlag)) bMatchFlag = bMatchFlag || partMatched; else bMatchFlag = bMatchFlag && partMatched; } } /** * [tFilterRow_1 begin ] stop */ /** * [tJavaRow_2 begin ] start */ ok_Hash.put("tJavaRow_2", false); start_Hash.put("tJavaRow_2", System.currentTimeMillis()); currentComponent = "tJavaRow_2"; int tos_count_tJavaRow_2 = 0; int nb_line_tJavaRow_2 = 0; /** * [tJavaRow_2 begin ] stop */ /** * [tExtractRegexFields_1 begin ] start */ ok_Hash.put("tExtractRegexFields_1", false); start_Hash.put("tExtractRegexFields_1", System.currentTimeMillis()); currentComponent = "tExtractRegexFields_1"; int tos_count_tExtractRegexFields_1 = 0; java.util.regex.Pattern pattern_tExtractRegexFields_1 = java.util.regex.Pattern .compile("http:\\/\\/bio2rdf.org\\/(.*)_vocabulary:Resource"); /** * [tExtractRegexFields_1 begin ] stop */ /** * [tExtractJSONFields_1 begin ] start */ ok_Hash.put("tExtractJSONFields_1", false); start_Hash.put("tExtractJSONFields_1", System.currentTimeMillis()); currentComponent = "tExtractJSONFields_1"; int tos_count_tExtractJSONFields_1 = 0; int nb_line_tExtractJSONFields_1 = 0; class ConvertJSONString_tExtractJSONFields_1 { final static int Brace = 0; // { final static int Bracket = 1; // [ private int barceType = -1; private String originalJsonString = ""; private String originalLoopString = ""; private String jsonString4XML = null; private String loopString4XML = null; private String additionRoot = null; public void barceType() { for (int c = 0; c < originalJsonString.length(); ++c) { if (originalJsonString.charAt(c) == '{') { barceType = Brace; break; } else if (originalJsonString.charAt(c) == '[') { barceType = Bracket; break; } } } public void setJsonString(String originalJsonString) { this.originalJsonString = originalJsonString; } public void setLoopString(String originalLoopString) { this.originalLoopString = originalLoopString; } public String getJsonString4XML() { return jsonString4XML; } public String getLoopString4XML() { if (loopString4XML.length() > 1 && loopString4XML.endsWith("/")) { loopString4XML = loopString4XML.substring(0, loopString4XML.length() - 1); } return loopString4XML; } public void setAdditionRoot(String additionRoot) { this.additionRoot = additionRoot; } public String getAdditionRoot() { return additionRoot; } public void generate() { barceType(); jsonString4XML = originalJsonString; loopString4XML = originalLoopString; if (Brace == barceType) { if (isNeedAddRoot(originalJsonString)) { jsonString4XML = "{ \"root\": " + originalJsonString + " }"; loopString4XML = "root" + originalLoopString; setAdditionRoot("root"); } } else if (Bracket == barceType) { jsonString4XML = "{ \"root\" : { \"object\": " + originalJsonString + " } }"; loopString4XML = "root/object" + originalLoopString; setAdditionRoot("object"); } } public boolean isNeedAddRoot(String originalJsonString) { boolean isNeedAddRoot = false; net.sf.json.JSONObject jso = net.sf.json.JSONObject.fromObject(originalJsonString); String jsonKey = ""; Object firstObject = null; if (jso.names().size() == 1) { jsonKey = jso.names().get(0).toString(); firstObject = jso.get(jsonKey); } if (jso.size() > 1 || (firstObject != null && firstObject instanceof net.sf.json.JSONArray && ((net.sf.json.JSONArray) firstObject).size() > 1)) { isNeedAddRoot = true; } return isNeedAddRoot; } } ConvertJSONString_tExtractJSONFields_1 cjs_tExtractJSONFields_1 = new ConvertJSONString_tExtractJSONFields_1(); de.odysseus.staxon.json.JsonXMLConfig config_tExtractJSONFields_1 = new de.odysseus.staxon.json.JsonXMLConfigBuilder() .multiplePI(false).build(); de.odysseus.staxon.json.JsonXMLInputFactory jsonXMLInputFactory_tExtractJSONFields_1 = new de.odysseus.staxon.json.JsonXMLInputFactory( config_tExtractJSONFields_1); javax.xml.stream.XMLOutputFactory xmlOutputFactory_tExtractJSONFields_1 = javax.xml.stream.XMLOutputFactory .newInstance(); boolean isGetWholeJson_tExtractJSONFields_1 = false; class OriginalJSONString_tExtractJSONFields_1 { } OriginalJSONString_tExtractJSONFields_1 originalJSONString_tExtractJSONFields_1 = new OriginalJSONString_tExtractJSONFields_1(); class XML_API_tExtractJSONFields_1 { public boolean isDefNull(org.dom4j.Node node) throws javax.xml.transform.TransformerException { if (node != null && node instanceof org.dom4j.Element) { org.dom4j.Attribute attri = ((org.dom4j.Element) node).attribute("nil"); if (attri != null && ("true").equals(attri.getText())) { return true; } } return false; } public boolean isMissing(org.dom4j.Node node) throws javax.xml.transform.TransformerException { return node == null ? true : false; } public boolean isEmpty(org.dom4j.Node node) throws javax.xml.transform.TransformerException { if (node != null) { return node.getText().length() == 0; } return false; } } String jsonStr_tExtractJSONFields_1 = ""; String xmlStr_tExtractJSONFields_1 = ""; XML_API_tExtractJSONFields_1 xml_api_tExtractJSONFields_1 = new XML_API_tExtractJSONFields_1(); /** * [tExtractJSONFields_1 begin ] stop */ /** * [tHttpRequest_1 begin ] start */ ok_Hash.put("tHttpRequest_1", false); start_Hash.put("tHttpRequest_1", System.currentTimeMillis()); currentComponent = "tHttpRequest_1"; int tos_count_tHttpRequest_1 = 0; /** * [tHttpRequest_1 begin ] stop */ /** * [tHttpRequest_1 main ] start */ currentComponent = "tHttpRequest_1"; java.net.URL url_tHttpRequest_1 = new java.net.URL("http://" + context.endpoint_namespace + ".bio2rdf.org/sparql?default-graph-uri=&query=PREFIX+void%3A+%3Chttp%3A%2F%2Frdfs.org%2Fns%2Fvoid%23%3E%0D%0APREFIX+ds%3A+%3Chttp%3A%2F%2Fbio2rdf.org%2Fbio2rdf.dataset_vocabulary%3A%3E%0D%0A%0D%0ASELECT+*%0D%0A+%7B+%5B%5D+void%3Asubset+%5B%0D%0A+++++++a+ds%3ADataset-Type-Count%3B%0D%0A+++++++void%3Aclass+%3Flink%3B%0D%0A+++++++void%3AdistinctEntities+%3FdistinctCount%3B%0D%0A+++%5D%0D%0A+++FILTER+regex%28str%28%3Flink%29%2C+%27.*bio2rdf.org%5C%5C%2F.*_vocabulary%3AResource%27%2C+%27i%27%29%0D%0A+%7D&format=application%2Fsparql-results%2Bjson&timeout=0&debug=on"); java.net.HttpURLConnection urlConn_tHttpRequest_1 = (java.net.HttpURLConnection) url_tHttpRequest_1 .openConnection(); urlConn_tHttpRequest_1.setRequestMethod("GET"); urlConn_tHttpRequest_1.setDoOutput(true); urlConn_tHttpRequest_1.setDoInput(true); urlConn_tHttpRequest_1.setUseCaches(false); urlConn_tHttpRequest_1.connect(); byte[] buffer_tHttpRequest_1 = new byte[1024]; int bos_buffer_tHttpRequest_1 = 0; StringBuilder sb_tHttpRequest_1 = new StringBuilder(); if (java.net.HttpURLConnection.HTTP_OK == (urlConn_tHttpRequest_1.getResponseCode())) { java.io.InputStream bis_tHttpRequest_1 = new java.io.BufferedInputStream( urlConn_tHttpRequest_1.getInputStream()); while ((bos_buffer_tHttpRequest_1 = bis_tHttpRequest_1.read(buffer_tHttpRequest_1)) != -1) { sb_tHttpRequest_1.append(new String(buffer_tHttpRequest_1, 0, bos_buffer_tHttpRequest_1)); } bis_tHttpRequest_1.close(); } else { System.err.println(urlConn_tHttpRequest_1.getResponseCode() + " " + urlConn_tHttpRequest_1.getResponseMessage()); } row6.ResponseContent = sb_tHttpRequest_1.toString(); urlConn_tHttpRequest_1.disconnect(); tos_count_tHttpRequest_1++; /** * [tHttpRequest_1 main ] stop */ /** * [tExtractJSONFields_1 main ] start */ currentComponent = "tExtractJSONFields_1"; if (row6.ResponseContent != null) {// C_01 jsonStr_tExtractJSONFields_1 = row6.ResponseContent.toString(); row7 = null; org.dom4j.io.SAXReader reader_tExtractJSONFields_1 = new org.dom4j.io.SAXReader(); org.dom4j.Document doc_tExtractJSONFields_1 = null; java.util.HashMap xmlNameSpaceMap_tExtractJSONFields_1 = new java.util.HashMap<String, String>(); org.dom4j.XPath x_tExtractJSONFields_1 = null; java.util.List<org.dom4j.tree.AbstractNode> nodeList_tExtractJSONFields_1 = null; boolean isStructError_tExtractJSONFields_1 = true; String loopQuery_tExtractJSONFields_1 = "/results/bindings"; String oraginalJsonStr_tExtractJSONFields_1 = jsonStr_tExtractJSONFields_1; cjs_tExtractJSONFields_1.setJsonString(jsonStr_tExtractJSONFields_1); cjs_tExtractJSONFields_1.setLoopString(loopQuery_tExtractJSONFields_1); java.io.ByteArrayInputStream bais_tExtractJSONFields_1 = null; java.io.ByteArrayOutputStream baos_tExtractJSONFields_1 = new java.io.ByteArrayOutputStream(); try { cjs_tExtractJSONFields_1.generate(); jsonStr_tExtractJSONFields_1 = cjs_tExtractJSONFields_1.getJsonString4XML(); loopQuery_tExtractJSONFields_1 = cjs_tExtractJSONFields_1.getLoopString4XML(); bais_tExtractJSONFields_1 = new ByteArrayInputStream( jsonStr_tExtractJSONFields_1.getBytes("UTF-8")); javax.xml.stream.XMLEventReader xmlEventReader_tExtractJSONFields_1 = jsonXMLInputFactory_tExtractJSONFields_1 .createXMLEventReader(bais_tExtractJSONFields_1); javax.xml.stream.XMLEventWriter xmLEventWriter_tExtractJSONFields_1 = xmlOutputFactory_tExtractJSONFields_1 .createXMLEventWriter(baos_tExtractJSONFields_1, "UTF-8"); xmLEventWriter_tExtractJSONFields_1.add(xmlEventReader_tExtractJSONFields_1); // convert json string to xml xmlStr_tExtractJSONFields_1 = baos_tExtractJSONFields_1.toString(); xmLEventWriter_tExtractJSONFields_1.close(); xmlEventReader_tExtractJSONFields_1.close(); doc_tExtractJSONFields_1 = reader_tExtractJSONFields_1 .read(new java.io.StringReader(xmlStr_tExtractJSONFields_1)); x_tExtractJSONFields_1 = doc_tExtractJSONFields_1 .createXPath(loopQuery_tExtractJSONFields_1); x_tExtractJSONFields_1.setNamespaceURIs(xmlNameSpaceMap_tExtractJSONFields_1); nodeList_tExtractJSONFields_1 = (java.util.List<org.dom4j.tree.AbstractNode>) x_tExtractJSONFields_1 .selectNodes(doc_tExtractJSONFields_1); isStructError_tExtractJSONFields_1 = false; } catch (java.lang.Exception ex_tExtractJSONFields_1) { System.err.println(ex_tExtractJSONFields_1.getMessage()); } finally { baos_tExtractJSONFields_1.close(); if (bais_tExtractJSONFields_1 != null) { bais_tExtractJSONFields_1.close(); } } org.dom4j.Node node_tExtractJSONFields_1 = null; String str_tExtractJSONFields_1 = ""; for (int i_tExtractJSONFields_1 = 0; isStructError_tExtractJSONFields_1 || (nodeList_tExtractJSONFields_1 != null && i_tExtractJSONFields_1 < nodeList_tExtractJSONFields_1 .size()); i_tExtractJSONFields_1++) { if (!isStructError_tExtractJSONFields_1) { row7 = null; row7 = new row7Struct(); org.dom4j.tree.AbstractNode temp_tExtractJSONFields_1 = nodeList_tExtractJSONFields_1 .get(i_tExtractJSONFields_1); nb_line_tExtractJSONFields_1++; try { org.dom4j.XPath xTmp0_tExtractJSONFields_1 = temp_tExtractJSONFields_1 .createXPath("link/value"); xTmp0_tExtractJSONFields_1.setNamespaceURIs(xmlNameSpaceMap_tExtractJSONFields_1); Object obj0_tExtractJSONFields_1 = xTmp0_tExtractJSONFields_1 .evaluate(temp_tExtractJSONFields_1); if (obj0_tExtractJSONFields_1 instanceof String || obj0_tExtractJSONFields_1 instanceof Number) { node_tExtractJSONFields_1 = temp_tExtractJSONFields_1; str_tExtractJSONFields_1 = String.valueOf(obj0_tExtractJSONFields_1); } else { node_tExtractJSONFields_1 = xTmp0_tExtractJSONFields_1 .selectSingleNode(temp_tExtractJSONFields_1); str_tExtractJSONFields_1 = xTmp0_tExtractJSONFields_1 .valueOf(temp_tExtractJSONFields_1); } if (xml_api_tExtractJSONFields_1.isDefNull(node_tExtractJSONFields_1)) { row7.link = null; } else if (xml_api_tExtractJSONFields_1.isEmpty(node_tExtractJSONFields_1)) { row7.link = ""; } else if (xml_api_tExtractJSONFields_1.isMissing(node_tExtractJSONFields_1)) { row7.link = null; } else { row7.link = str_tExtractJSONFields_1; } org.dom4j.XPath xTmp1_tExtractJSONFields_1 = temp_tExtractJSONFields_1 .createXPath("distinctCount/value"); xTmp1_tExtractJSONFields_1.setNamespaceURIs(xmlNameSpaceMap_tExtractJSONFields_1); Object obj1_tExtractJSONFields_1 = xTmp1_tExtractJSONFields_1 .evaluate(temp_tExtractJSONFields_1); if (obj1_tExtractJSONFields_1 instanceof String || obj1_tExtractJSONFields_1 instanceof Number) { node_tExtractJSONFields_1 = temp_tExtractJSONFields_1; str_tExtractJSONFields_1 = String.valueOf(obj1_tExtractJSONFields_1); } else { node_tExtractJSONFields_1 = xTmp1_tExtractJSONFields_1 .selectSingleNode(temp_tExtractJSONFields_1); str_tExtractJSONFields_1 = xTmp1_tExtractJSONFields_1 .valueOf(temp_tExtractJSONFields_1); } if (xml_api_tExtractJSONFields_1.isDefNull(node_tExtractJSONFields_1)) { row7.count = null; } else if (xml_api_tExtractJSONFields_1.isEmpty(node_tExtractJSONFields_1)) { row7.count = ""; } else if (xml_api_tExtractJSONFields_1.isMissing(node_tExtractJSONFields_1)) { row7.count = null; } else { row7.count = str_tExtractJSONFields_1; } } catch (java.lang.Exception ex_tExtractJSONFields_1) { System.err.println(ex_tExtractJSONFields_1.getMessage()); row7 = null; } } isStructError_tExtractJSONFields_1 = false; tos_count_tExtractJSONFields_1++; /** * [tExtractJSONFields_1 main ] stop */ // Start of branch "row7" if (row7 != null) { /** * [tExtractRegexFields_1 main ] start */ currentComponent = "tExtractRegexFields_1"; row8 = null; if (row7.link != null) {// C_01 java.util.regex.Matcher matcher_tExtractRegexFields_1 = pattern_tExtractRegexFields_1 .matcher(row7.link); int groupCount_tExtractRegexFields_1 = matcher_tExtractRegexFields_1.groupCount(); while (matcher_tExtractRegexFields_1.find()) { try { row8 = new row8Struct(); row8.count = row7.count; String temp_tExtractRegexFields_1 = null; row8.linkNamespace = groupCount_tExtractRegexFields_1 <= 0 ? "" : matcher_tExtractRegexFields_1.group(1); } catch (java.lang.Exception ex_tExtractRegexFields_1) { throw (ex_tExtractRegexFields_1); } tos_count_tExtractRegexFields_1++; /** * [tExtractRegexFields_1 main ] stop */ // Start of branch "row8" if (row8 != null) { /** * [tJavaRow_2 main ] start */ currentComponent = "tJavaRow_2"; // Code gnr selon le schmas d'entre // et de sortie row9.link = row8.linkNamespace; row9.stat = row8.count; nb_line_tJavaRow_2++; tos_count_tJavaRow_2++; /** * [tJavaRow_2 main ] stop */ /** * [tFilterRow_1 main ] start */ currentComponent = "tFilterRow_1"; row10 = null; Operator_tFilterRow_1 ope_tFilterRow_1 = new Operator_tFilterRow_1("&&"); ope_tFilterRow_1.matches((// code sample : use // row9 to define // the condition. // row9.columnName1.equals("foo") // ||!(row9.columnName2.equals("bar")) // replace the following // expression by your // own filter condition !row9.link.contains(".") && !row9.link.contains(" ") && !row9.link.equals(context.endpoint_namespace)), "advanced condition failed"); if (ope_tFilterRow_1.getMatchFlag()) { if (row10 == null) { row10 = new row10Struct(); } row10.link = row9.link; row10.stat = row9.stat; nb_line_ok_tFilterRow_1++; } else { nb_line_reject_tFilterRow_1++; } nb_line_tFilterRow_1++; tos_count_tFilterRow_1++; /** * [tFilterRow_1 main ] stop */ // Start of branch "row10" if (row10 != null) { /** * [tLogRow_2 main ] start */ currentComponent = "tLogRow_2"; row5 = row10; tos_count_tLogRow_2++; /** * [tLogRow_2 main ] stop */ /** * [tBufferOutput_1 main ] start */ currentComponent = "tBufferOutput_1"; String[] row_tBufferOutput_1 = new String[] { "", "", }; if (row5.link != null) { row_tBufferOutput_1[0] = row5.link; } else { row_tBufferOutput_1[0] = null; } if (row5.stat != null) { row_tBufferOutput_1[1] = row5.stat; } else { row_tBufferOutput_1[1] = null; } globalBuffer.add(row_tBufferOutput_1); tos_count_tBufferOutput_1++; /** * [tBufferOutput_1 main ] stop */ } // End of branch "row10" } // End of branch "row8" // end for } } // C_01 } // End of branch "row7" // end for } } // C_01 /** * [tHttpRequest_1 end ] start */ currentComponent = "tHttpRequest_1"; ok_Hash.put("tHttpRequest_1", true); end_Hash.put("tHttpRequest_1", System.currentTimeMillis()); /** * [tHttpRequest_1 end ] stop */ /** * [tExtractJSONFields_1 end ] start */ currentComponent = "tExtractJSONFields_1"; globalMap.put("tExtractJSONFields_1_NB_LINE", nb_line_tExtractJSONFields_1); ok_Hash.put("tExtractJSONFields_1", true); end_Hash.put("tExtractJSONFields_1", System.currentTimeMillis()); /** * [tExtractJSONFields_1 end ] stop */ /** * [tExtractRegexFields_1 end ] start */ currentComponent = "tExtractRegexFields_1"; ok_Hash.put("tExtractRegexFields_1", true); end_Hash.put("tExtractRegexFields_1", System.currentTimeMillis()); /** * [tExtractRegexFields_1 end ] stop */ /** * [tJavaRow_2 end ] start */ currentComponent = "tJavaRow_2"; globalMap.put("tJavaRow_2_NB_LINE", nb_line_tJavaRow_2); ok_Hash.put("tJavaRow_2", true); end_Hash.put("tJavaRow_2", System.currentTimeMillis()); /** * [tJavaRow_2 end ] stop */ /** * [tFilterRow_1 end ] start */ currentComponent = "tFilterRow_1"; globalMap.put("tFilterRow_1_NB_LINE", nb_line_tFilterRow_1); globalMap.put("tFilterRow_1_NB_LINE_OK", nb_line_ok_tFilterRow_1); globalMap.put("tFilterRow_1_NB_LINE_REJECT", nb_line_reject_tFilterRow_1); ok_Hash.put("tFilterRow_1", true); end_Hash.put("tFilterRow_1", System.currentTimeMillis()); /** * [tFilterRow_1 end ] stop */ /** * [tLogRow_2 end ] start */ currentComponent = "tLogRow_2"; ok_Hash.put("tLogRow_2", true); end_Hash.put("tLogRow_2", System.currentTimeMillis()); /** * [tLogRow_2 end ] stop */ /** * [tBufferOutput_1 end ] start */ currentComponent = "tBufferOutput_1"; ok_Hash.put("tBufferOutput_1", true); end_Hash.put("tBufferOutput_1", System.currentTimeMillis()); /** * [tBufferOutput_1 end ] stop */ } // end the resume } catch (java.lang.Exception e) { TalendException te = new TalendException(e, currentComponent, globalMap); throw te; } catch (java.lang.Error error) { throw error; } finally { try { /** * [tHttpRequest_1 finally ] start */ currentComponent = "tHttpRequest_1"; /** * [tHttpRequest_1 finally ] stop */ /** * [tExtractJSONFields_1 finally ] start */ currentComponent = "tExtractJSONFields_1"; /** * [tExtractJSONFields_1 finally ] stop */ /** * [tExtractRegexFields_1 finally ] start */ currentComponent = "tExtractRegexFields_1"; /** * [tExtractRegexFields_1 finally ] stop */ /** * [tJavaRow_2 finally ] start */ currentComponent = "tJavaRow_2"; /** * [tJavaRow_2 finally ] stop */ /** * [tFilterRow_1 finally ] start */ currentComponent = "tFilterRow_1"; /** * [tFilterRow_1 finally ] stop */ /** * [tLogRow_2 finally ] start */ currentComponent = "tLogRow_2"; /** * [tLogRow_2 finally ] stop */ /** * [tBufferOutput_1 finally ] start */ currentComponent = "tBufferOutput_1"; /** * [tBufferOutput_1 finally ] stop */ } catch (java.lang.Exception e) { // ignore } catch (java.lang.Error error) { // ignore } resourceMap = null; } globalMap.put("tHttpRequest_1_SUBPROCESS_STATE", 1); } public String resuming_logs_dir_path = null; public String resuming_checkpoint_path = null; public String parent_part_launcher = null; private String resumeEntryMethodName = null; private boolean globalResumeTicket = false; public boolean watch = false; // portStats is null, it means don't execute the statistics public Integer portStats = null; public int portTraces = 4334; public String clientHost; public String defaultClientHost = "localhost"; public String contextStr = "Default"; public boolean isDefaultContext = true; public String pid = "0"; public String rootPid = null; public String fatherPid = null; public String fatherNode = null; public long startTime = 0; public boolean isChildJob = false; public String log4jLevel = ""; private boolean execStat = true; private ThreadLocal<java.util.Map<String, String>> threadLocal = new ThreadLocal<java.util.Map<String, String>>() { protected java.util.Map<String, String> initialValue() { java.util.Map<String, String> threadRunResultMap = new java.util.HashMap<String, String>(); threadRunResultMap.put("errorCode", null); threadRunResultMap.put("status", ""); return threadRunResultMap; }; }; private java.util.Properties context_param = new java.util.Properties(); public java.util.Map<String, Object> parentContextMap = new java.util.HashMap<String, Object>(); public String status = ""; public static void main(String[] args) { final datahub_get_stats datahub_get_statsClass = new datahub_get_stats(); int exitCode = datahub_get_statsClass.runJobInTOS(args); System.exit(exitCode); } public String[][] runJob(String[] args) { int exitCode = runJobInTOS(args); String[][] bufferValue = (String[][]) globalBuffer.toArray(new String[globalBuffer.size()][]); return bufferValue; } public boolean hastBufferOutputComponent() { boolean hastBufferOutput = false; hastBufferOutput = true; return hastBufferOutput; } public int runJobInTOS(String[] args) { // reset status status = ""; String lastStr = ""; for (String arg : args) { if (arg.equalsIgnoreCase("--context_param")) { lastStr = arg; } else if (lastStr.equals("")) { evalParam(arg); } else { evalParam(lastStr + " " + arg); lastStr = ""; } } if (clientHost == null) { clientHost = defaultClientHost; } if (pid == null || "0".equals(pid)) { pid = TalendString.getAsciiRandomString(6); } if (rootPid == null) { rootPid = pid; } if (fatherPid == null) { fatherPid = pid; } else { isChildJob = true; } try { // call job/subjob with an existing context, like: // --context=production. if without this parameter, there will use // the default context instead. java.io.InputStream inContext = datahub_get_stats.class.getClassLoader() .getResourceAsStream("bio2rdf/datahub_get_stats_0_1/contexts/" + contextStr + ".properties"); if (isDefaultContext && inContext == null) { } else { if (inContext != null) { // defaultProps is in order to keep the original context // value defaultProps.load(inContext); inContext.close(); context = new ContextProperties(defaultProps); } else { // print info and job continue to run, for case: // context_param is not empty. System.err.println("Could not find the context " + contextStr); } } if (!context_param.isEmpty()) { context.putAll(context_param); } context.inputFile = (String) context.getProperty("inputFile"); context.endpoint_namespace = (String) context.getProperty("endpoint_namespace"); } catch (java.io.IOException ie) { System.err.println("Could not load context " + contextStr); ie.printStackTrace(); } // get context value from parent directly if (parentContextMap != null && !parentContextMap.isEmpty()) { if (parentContextMap.containsKey("inputFile")) { context.inputFile = (String) parentContextMap.get("inputFile"); } if (parentContextMap.containsKey("endpoint_namespace")) { context.endpoint_namespace = (String) parentContextMap.get("endpoint_namespace"); } } // Resume: init the resumeUtil resumeEntryMethodName = ResumeUtil.getResumeEntryMethodName(resuming_checkpoint_path); resumeUtil = new ResumeUtil(resuming_logs_dir_path, isChildJob, rootPid); resumeUtil.initCommonInfo(pid, rootPid, fatherPid, projectName, jobName, contextStr, jobVersion); // Resume: jobStart resumeUtil.addLog("JOB_STARTED", "JOB:" + jobName, parent_part_launcher, Thread.currentThread().getId() + "", "", "", "", "", resumeUtil.convertToJsonText(context)); java.util.concurrent.ConcurrentHashMap<Object, Object> concurrentHashMap = new java.util.concurrent.ConcurrentHashMap<Object, Object>(); globalMap.put("concurrentHashMap", concurrentHashMap); long startUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); long endUsedMemory = 0; long end = 0; startTime = System.currentTimeMillis(); this.globalResumeTicket = true;// to run tPreJob this.globalResumeTicket = false;// to run others jobs try { errorCode = null; tHttpRequest_1Process(globalMap); if (!"failure".equals(status)) { status = "end"; } } catch (TalendException e_tHttpRequest_1) { globalMap.put("tHttpRequest_1_SUBPROCESS_STATE", -1); e_tHttpRequest_1.printStackTrace(); } this.globalResumeTicket = true;// to run tPostJob end = System.currentTimeMillis(); if (watch) { System.out.println((end - startTime) + " milliseconds"); } endUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); if (false) { System.out.println( (endUsedMemory - startUsedMemory) + " bytes memory increase when running : datahub_get_stats"); } int returnCode = 0; if (errorCode == null) { returnCode = status != null && status.equals("failure") ? 1 : 0; } else { returnCode = errorCode.intValue(); } resumeUtil.addLog("JOB_ENDED", "JOB:" + jobName, parent_part_launcher, Thread.currentThread().getId() + "", "", "" + returnCode, "", "", ""); return returnCode; } public void destroy() { } private java.util.Map<String, Object> getSharedConnections4REST() { java.util.Map<String, Object> connections = new java.util.HashMap<String, Object>(); return connections; } private void evalParam(String arg) { if (arg.startsWith("--resuming_logs_dir_path")) { resuming_logs_dir_path = arg.substring(25); } else if (arg.startsWith("--resuming_checkpoint_path")) { resuming_checkpoint_path = arg.substring(27); } else if (arg.startsWith("--parent_part_launcher")) { parent_part_launcher = arg.substring(23); } else if (arg.startsWith("--watch")) { watch = true; } else if (arg.startsWith("--stat_port=")) { String portStatsStr = arg.substring(12); if (portStatsStr != null && !portStatsStr.equals("null")) { portStats = Integer.parseInt(portStatsStr); } } else if (arg.startsWith("--trace_port=")) { portTraces = Integer.parseInt(arg.substring(13)); } else if (arg.startsWith("--client_host=")) { clientHost = arg.substring(14); } else if (arg.startsWith("--context=")) { contextStr = arg.substring(10); isDefaultContext = false; } else if (arg.startsWith("--father_pid=")) { fatherPid = arg.substring(13); } else if (arg.startsWith("--root_pid=")) { rootPid = arg.substring(11); } else if (arg.startsWith("--father_node=")) { fatherNode = arg.substring(14); } else if (arg.startsWith("--pid=")) { pid = arg.substring(6); } else if (arg.startsWith("--context_param")) { String keyValue = arg.substring(16); int index = -1; if (keyValue != null && (index = keyValue.indexOf('=')) > -1) { if (fatherPid == null) { context_param.put(keyValue.substring(0, index), replaceEscapeChars(keyValue.substring(index + 1))); } else { // the subjob won't escape the especial chars context_param.put(keyValue.substring(0, index), keyValue.substring(index + 1)); } } } else if (arg.startsWith("--log4jLevel=")) { log4jLevel = arg.substring(13); } } private final String[][] escapeChars = { { "\\\\", "\\" }, { "\\n", "\n" }, { "\\'", "\'" }, { "\\r", "\r" }, { "\\f", "\f" }, { "\\b", "\b" }, { "\\t", "\t" } }; private String replaceEscapeChars(String keyValue) { if (keyValue == null || ("").equals(keyValue.trim())) { return keyValue; } StringBuilder result = new StringBuilder(); int currIndex = 0; while (currIndex < keyValue.length()) { int index = -1; // judege if the left string includes escape chars for (String[] strArray : escapeChars) { index = keyValue.indexOf(strArray[0], currIndex); if (index >= 0) { result.append(keyValue.substring(currIndex, index + strArray[0].length()).replace(strArray[0], strArray[1])); currIndex = index + strArray[0].length(); break; } } // if the left string doesn't include escape chars, append the left // into the result if (index < 0) { result.append(keyValue.substring(currIndex)); currIndex = currIndex + keyValue.length(); } } return result.toString(); } public Integer getErrorCode() { return errorCode; } public String getStatus() { return status; } ResumeUtil resumeUtil = null; } /************************************************************************************************ * 65622 characters generated by Talend Open Studio for Data Integration on the * 11 aot 2014 16:32:21 EDT ************************************************************************************************/