com.novartis.opensource.yada.format.RESTResultDelimitedConverter Maven / Gradle / Ivy
/**
* Copyright 2016 Novartis Institutes for BioMedical Research Inc.
* 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 com.novartis.opensource.yada.format;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;
import com.novartis.opensource.yada.YADAQueryResult;
import com.novartis.opensource.yada.YADARequest;
import com.novartis.opensource.yada.YADAResourceException;
import com.novartis.opensource.yada.io.YADAIOException;
/**
* @author David Varon
* @since 4.0.0
*/
public class RESTResultDelimitedConverter extends AbstractConverter {
/**
* Default constructor
* @throws YADAResourceException when the path to {@code r.js} or {@code harmony.js} is corrupt
* @throws YADAIOException when the path to {@code r.js} or {@code harmony.js} can't be read
* @throws YADAConverterException when the Rhino javascript engine throws an error
*/
public RESTResultDelimitedConverter() throws YADAResourceException, YADAIOException, YADAConverterException {
// default constructor
setHarmonizer(new Harmonizer());
}
/**
* Constructor with {@link YADAQueryResult}
* @param yqr the container for result processing artifacts
* @throws YADAResourceException when the path to {@code r.js} or {@code harmony.js} is corrupt
* @throws YADAIOException when the path to {@code r.js} or {@code harmony.js} can't be read
* @throws YADAConverterException when the Rhino javascript engine throws an error
*/
public RESTResultDelimitedConverter(YADAQueryResult yqr) throws YADAResourceException, YADAIOException, YADAConverterException {
this.setYADAQueryResult(yqr);
setHarmonizer(new Harmonizer());
}
/**
* Creates a delimited result object using {@code newColSep} as a column
* separator and {@code newRecSep} as a row separator.
*
* @see com.novartis.opensource.yada.format.AbstractConverter#convert(java.lang.Object,
* java.lang.String, java.lang.String)
*/
@Override
public Object convert(Object o, String newColSep, String newRecSep)
throws YADAConverterException {
StringBuffer result = new StringBuffer();
this.colsep = newColSep;
this.recsep = newRecSep;
try
{
getDelimitedRows(o);
}
catch (JSONException e)
{
String msg = "Unable to read Harmony Map";
throw new YADAConverterException(msg, e);
}
return result;
}
/**
* Parses global harmony map for duplicate values, and removes key/value pairs that
* are not present in local harmony map.
* @return the parsed global harmony map
* @since 6.1.0
*/
@Override
public Object getHarmonyMap()
{
JSONObject globMap = (JSONObject)this.harmonyMap;
JSONObject local = new JSONObject(getYADAQueryResult().getYADAQueryParamValue(YADARequest.PS_HARMONYMAP));
ArrayList © 2015 - 2025 Weber Informatics LLC | Privacy Policy