<commit_before>/*******************************************************************************
 * In the Hi-WAY project we propose a novel approach of executing scientific
 * workflows processing Big Data, as found in NGS applications, on distributed
 * computational infrastructures. The Hi-WAY software stack comprises the func-
 * tional workflow language Cuneiform as well as the Hi-WAY ApplicationMaster
 * for Apache Hadoop 2.x (YARN).
 *
 * List of Contributors:
 *
 * <NAME> (HU Berlin)
 * <NAME> (HU Berlin)
 * <NAME> (HU Berlin)
 *
 * <NAME> is funded by the European Commission through the BiobankCloud
 * project. <NAME> is funded by the Deutsche Forschungsgemeinschaft through
 * research training group SOAMED (GRK 1651).
 *
 * Copyright 2014 Humboldt-Universität zu Berlin
 *
 * 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 de.huberlin.cuneiform.dag;

import java.util.UUID;

import org.json.JSONException;
import org.json.JSONObject;


public class JsonReportEntry {
	
	public static final String KEY_INVOC_TIME = "invoc-time";
	public static final String KEY_FILE_SIZE_STAGEIN = "file-size-stagein";
	public static final String KEY_FILE_SIZE_STAGEOUT = "file-size-stageout";
	public static final String KEY_INVOC_OUTPUT = "invoc-output";
	public static final String KEY_INVOC_STDOUT = "invoc-stdout";
	public static final String KEY_INVOC_STDERR = "invoc-stderr";
	public static final String KEY_INVOC_USER = "invoc-user";
	
	public static final String ATT_INVOCID = "invocId";
	public static final String ATT_KEY = "key";
	public static final String ATT_RUNID = "runId";
	public static final String ATT_VALUE = "value";
	public static final String ATT_TASKNAME = "taskname";
	public static final String ATT_TASKID = "taskId";
	public static final String ATT_TIMESTAMP = "timestamp";
	public static final String ATT_LANG = "lang";

	private UUID runId;
	private Long invocId;
	private String key;
	private String value;
	private String taskname;
	private Long taskId;
	private long timestamp;
	private String lang;
	
	public JsonReportEntry(
		long timestamp, UUID runId, Long taskId, String taskname,
		String lang, Long invocId, String key, String rawValue ) {
		
		setTimestamp( timestamp );
		setRunId( runId );
		setTaskId( taskId );
		setTaskname( taskname );
		setInvocId( invocId );
		setLang( lang );
		setKey( key );
		setValueFromRawString( rawValue );
	}
	
	public JsonReportEntry(
		UUID runId, Long taskId, String taskname,
		String lang, Long invocId, String key, String rawValue ) {
		this( System.currentTimeMillis(), runId, taskId, taskname, lang, invocId, key, rawValue );
	}
		
	public JsonReportEntry(
		long timestamp, UUID runId, Long taskId, String taskname,
		String lang, Long invocId, String key, JSONObject obj ) {
			
		setTimestamp( timestamp );
		setRunId( runId );
		setTaskId( taskId );
		setTaskname( taskname );
		setInvocId( invocId );
		setLang( lang );
		setKey( key );
		setValueFromJsonObj( obj );
	}
	
	public JsonReportEntry(
		UUID runId, Long taskId, String taskname,
		String lang, Long invocId, String key, JSONObject obj ) {
		this( System.currentTimeMillis(), runId, taskId, taskname, lang, invocId, key, obj );
	}
	
	public JsonReportEntry( String raw ) throws JSONException {
		
		JSONObject obj, valueObj;
		String valueString;
		
		try {
			obj = new JSONObject( raw );
			
			setTimestamp( obj.getLong( ATT_TIMESTAMP ) );
			setTaskId( obj.getLong( ATT_TASKID ) );
			
			if( obj.has( ATT_TASKNAME ) )
				setTaskname( obj.getString( ATT_TASKNAME ) );
			
			setLang( obj.getString( ATT_LANG ) );
			setInvocId( obj.getLong( ATT_INVOCID ) );
			setKey( obj.getString( ATT_KEY ) );
			
			try {
				valueObj = obj.getJSONObject( ATT_VALUE );
				setValueFromJsonObj( valueObj );
			}
			catch( JSONException e ) {
				valueString = obj.getString( ATT_VALUE );
				setValueFromRawString( valueString );<commit_msg>JsonReportEntry null field handling improved.<commit_after>/*******************************************************************************
 * In the Hi-WAY project we propose a novel approach of executing scientific
 * workflows processing Big Data, as found in NGS applications, on distributed
 * computational infrastructures. The Hi-WAY software stack comprises the func-
 * tional workflow language Cuneiform as well as the Hi-WAY ApplicationMaster
 * for Apache Hadoop 2.x (YARN).
 *
 * List of Contributors:
 *
 * <NAME> (HU Berlin)
 * <NAME> (HU Berlin)
 * <NAME> (HU Berlin)
 *
 * <NAME> is funded by the European Commission through the BiobankCloud
 * project. <NAME> is funded by the Deutsche Forschungsgemeinschaft through
 * research training group SOAMED (GRK 1651).
 *
 * Copyright 2014 Humboldt-Universität zu Berlin
 *
 * 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 de.huberlin.cuneiform.dag;

import java.util.UUID;

import org.json.JSONException;
import org.json.JSONObject;


public class JsonReportEntry {
	
	public static final String KEY_INVOC_TIME = "invoc-time";
	public static final String KEY_FILE_SIZE_STAGEIN = "file-size-stagein";
	public static final String KEY_FILE_SIZE_STAGEOUT = "file-size-stageout";
	public static final String KEY_INVOC_OUTPUT = "invoc-output";
	public static final String KEY_INVOC_STDOUT = "invoc-stdout";
	public static final String KEY_INVOC_STDERR = "invoc-stderr";
	public static final String KEY_INVOC_USER = "invoc-user";
	
	public static final String ATT_INVOCID = "invocId";
	public static final String ATT_KEY = "key";
	public static final String ATT_RUNID = "runId";
	public static final String ATT_VALUE = "value";
	public static final String ATT_TASKNAME = "taskname";
	public static final String ATT_TASKID = "taskId";
	public static final String ATT_TIMESTAMP = "timestamp";
	public static final String ATT_LANG = "lang";

	private UUID runId;
	private Long invocId;
	private String key;
	private String value;
	private String taskname;
	private Long taskId;
	private long timestamp;
	private String lang;
	
	public JsonReportEntry(
		long timestamp, UUID runId, Long taskId, String taskname,
		String lang, Long invocId, String key, String rawValue ) {
		
		setTimestamp( timestamp );
		setRunId( runId );
		setTaskId( taskId );
		setTaskname( taskname );
		setInvocId( invocId );
		setLang( lang );
		setKey( key );
		setValueFromRawString( rawValue );
	}
	
	public JsonReportEntry(
		UUID runId, Long taskId, String taskname,
		String lang, Long invocId, String key, String rawValue ) {
		this( System.currentTimeMillis(), runId, taskId, taskname, lang, invocId, key, rawValue );
	}
		
	public JsonReportEntry(
		long timestamp, UUID runId, Long taskId, String taskname,
		String lang, Long invocId, String key, JSONObject obj ) {
			
		setTimestamp( timestamp );
		setRunId( runId );
		setTaskId( taskId );
		setTaskname( taskname );
		setInvocId( invocId );
		setLang( lang );
		setKey( key );
		setValueFromJsonObj( obj );
	}
	
	public JsonReportEntry(
		UUID runId, Long taskId, String taskname,
		String lang, Long invocId, String key, JSONObject obj ) {
		this( System.currentTimeMillis(), runId, taskId, taskname, lang, invocId, key, obj );
	}
	
	public JsonReportEntry( String raw ) throws JSONException {
		
		JSONObject obj, valueObj;
		String valueString;
		
		try {
			obj = new JSONObject( raw );
			
			setTimestamp( obj.getLong( ATT_TIMESTAMP ) );

			if( obj.has( ATT_TASKID ) )
				if( !obj.isNull( ATT_TASKID ) )
					setTaskId( obj.getLong( ATT_TASKID ) );
			
			if( obj.has( ATT_TASKNAME ) )
				if( !obj.isNull( ATT_TASKNAME ) )
					setTaskname( obj.getString( ATT_TASKNAME ) );
			
			if( obj.has( ATT_LANG ) )
				if( !obj.isNull( ATT_LANG ) )
					setLang( obj.getString( ATT_LANG ) );
			
			if( obj.has( ATT_INVOCID ) )
				if( !obj.isNull( ATT_INVOCID ) )
					setInvocId( obj.getLong( ATT_INVOCID ) );
			
			setKey( obj.getString( ATT_KEY ) );
			
			try {
				valueObj = obj.getJSONObject( ATT_VALUE );
				setValueFromJsonObj( valueObj );
			}
			catch( JSONException e ) {
				valueString = obj.getString( ATT_VALUE );
				setValueFromRawString( valueString );
{'fraction_non_alphanumeric': 0.11855056787452677, 'fraction_numerical': 0.002812330989724175, 'mean_word_length': 4.209014084507042, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2651154', 'n_tokens_mistral': 3075, 'n_tokens_neox': 2757, 'n_words': 949}