use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project dishevelled-bio by heuermh.
the class TraversePaths method call.
@Override
public Integer call() throws Exception {
BufferedReader reader = null;
PrintWriter writer = null;
try {
reader = reader(inputGfa1File);
writer = writer(outputGfa1File);
final PrintWriter w = writer;
Gfa1Reader.stream(reader, new Gfa1Listener() {
@Override
public boolean record(final Gfa1Record gfa1Record) {
Gfa1Writer.write(gfa1Record, w);
if (gfa1Record instanceof Path) {
Path path = (Path) gfa1Record;
int size = path.getSegments().size();
Reference source = null;
Reference target = null;
String overlap = null;
for (int i = 0; i < size; i++) {
target = path.getSegments().get(i);
if (i > 0) {
overlap = (path.getOverlaps() != null && path.getOverlaps().size() > i) ? path.getOverlaps().get(i - 1) : null;
}
if (source != null) {
Traversal traversal = new Traversal(path.getName(), i - 1, source, target, overlap, EMPTY_ANNOTATIONS);
Gfa1Writer.write(traversal, w);
}
source = target;
}
}
return true;
}
});
return 0;
} finally {
try {
reader.close();
} catch (Exception e) {
// ignore
}
try {
writer.close();
} catch (Exception e) {
// ignore
}
}
}
use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project cel-java by projectnessie.
the class Checker method resolveOverload.
OverloadResolution resolveOverload(Location loc, Decl fn, Expr.Builder target, List<Expr.Builder> args) {
List<Type> argTypes = new ArrayList<>();
if (target != null) {
Type argType = getType(target);
if (argType == null) {
throw new ErrException("Could not resolve type for target '%s'", target);
}
argTypes.add(argType);
}
for (int i = 0; i < args.size(); i++) {
Expr.Builder arg = args.get(i);
Type argType = getType(arg);
if (argType == null) {
throw new ErrException("Could not resolve type for argument %d '%s'", i, arg);
}
argTypes.add(argType);
}
Type resultType = null;
Reference checkedRef = null;
for (Overload overload : fn.getFunction().getOverloadsList()) {
if ((target == null && overload.getIsInstanceFunction()) || (target != null && !overload.getIsInstanceFunction())) {
// not a compatible call style.
continue;
}
Type overloadType = Decls.newFunctionType(overload.getResultType(), overload.getParamsList());
if (overload.getTypeParamsCount() > 0) {
// Instantiate overload's type with fresh type variables.
Mapping substitutions = newMapping();
for (String typePar : overload.getTypeParamsList()) {
substitutions.add(Decls.newTypeParamType(typePar), newTypeVar());
}
overloadType = substitute(substitutions, overloadType, false);
}
List<Type> candidateArgTypes = overloadType.getFunction().getArgTypesList();
if (isAssignableList(argTypes, candidateArgTypes)) {
if (checkedRef == null) {
checkedRef = newFunctionReference(Collections.singletonList(overload.getOverloadId()));
} else {
checkedRef = checkedRef.toBuilder().addOverloadId(overload.getOverloadId()).build();
}
// First matching overload, determines result type.
Type fnResultType = substitute(mappings, overloadType.getFunction().getResultType(), false);
if (resultType == null) {
resultType = fnResultType;
} else if (!isDyn(resultType) && !fnResultType.equals(resultType)) {
resultType = Decls.Dyn;
}
}
}
if (resultType == null) {
errors.noMatchingOverload(loc, fn.getName(), argTypes, target != null);
// resultType = Decls.Error;
return null;
}
return newResolution(checkedRef, resultType);
}
use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project geotoolkit by Geomatys.
the class ConvertersTestUtils method initAndRunOutputConversion.
/**
* Helper method to initialize a converter and run with its parameters.
*
* The converters are the one that convert Geometry or Feature types to
* Complex or Reference.
*
* The method is in charge of setting up the parameters map, the resource
* (either a java URL or String containg json datas) and calling conversion
* method.
*
* @param <SourceType> type of the input data in the conversion
* @param <TargetType> type of the output data in the conversion
* @param sourceClass class of the input data in the conversion
* @param targetClass class of the output dat in the conversion
* @param resource resource to give as input to the converter (must be of the
* same type as SourceType)
* @param mimeType mime type of the input data
* @param encoding encoding of the input data
*
* @return an instance of TargetType which is the result of a call to the converter
*
* @throws IOException on reading the test resource
* @throws IllegalArgumentException when mimeType or encoding is empty
* @throws NullArgumentException when an argument is null
*/
public static <SourceType, TargetType> TargetType initAndRunOutputConversion(Class sourceClass, Class targetClass, Object resource, String mimeType, String encoding) throws IOException {
ArgumentChecks.ensureNonNull("sourceClass", sourceClass);
ArgumentChecks.ensureNonNull("targetClass", targetClass);
ArgumentChecks.ensureNonNull("resource", resource);
ArgumentChecks.ensureNonEmpty("mimeType", mimeType);
ArgumentChecks.ensureNonEmpty("encoding", encoding);
// Get converter
final WPSObjectConverter<SourceType, TargetType> converter = WPSConverterRegistry.getInstance().getConverter(sourceClass, targetClass);
// Setup the parameters map
Path tmpDirPath;
Map<String, Object> parametersMap = null;
if (targetClass.equals(Data.class))
parametersMap = ConvertersTestUtils.createParameters(mimeType, encoding);
else if (targetClass.equals(Reference.class)) {
tmpDirPath = Files.createTempDirectory(UUID.randomUUID().toString());
parametersMap = ConvertersTestUtils.createParameters(mimeType, encoding, tmpDirPath.toUri().toString(), WPSIO.IOType.OUTPUT.toString());
} else
fail();
return converter.convert((SourceType) resource, parametersMap);
}
use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project geotoolkit by Geomatys.
the class ConvertersTestUtils method initAndRunInputConversion.
/**
* Helper method to initialize a converter and run with its parameters.
*
* The converters are the ones that convert Complex or reference to Geometry
* or Feature types.
*
* The method is in charge of setting up the parameters map, the resource
* (either a java URL or String containg json datas) and calling conversion
* method.
*
* @param <SourceType> type of the input data in the conversion
* @param <TargetType> type of the output data in the conversion
* @param sourceClass class of the input data in the conversion
* @param targetClass class of the output dat in the conversion
* @param resourcePath url to the resource file to read
* @param mimeType mime type of the input data
* @param encoding encoding of the input data
* @param schema schema for the input data (only arguments that can be null)
* @return an instance of TargetType which is the result of a call to the converter
* @throws IOException on reading the test resource
* @throws IllegalArgumentException when one of the String arguments is null
* @throws NullArgumentException when one of the arguments is null
*/
public static <SourceType, TargetType> TargetType initAndRunInputConversion(Class sourceClass, Class targetClass, String resourcePath, String mimeType, String encoding, String schema) throws IOException {
ArgumentChecks.ensureNonNull("sourceClass", sourceClass);
ArgumentChecks.ensureNonNull("targetClass", targetClass);
ArgumentChecks.ensureNonEmpty("resourcePath", resourcePath);
ArgumentChecks.ensureNonEmpty("mimeType", mimeType);
ArgumentChecks.ensureNonEmpty("encoding", encoding);
// Get the converter to test
final WPSObjectConverter<SourceType, TargetType> converter = WPSConverterRegistry.getInstance().getConverter(sourceClass, targetClass);
// Setup parameters map
final Map<String, Object> param = ConvertersTestUtils.createParameters(mimeType, encoding);
// Setup the resource and run conversion
if (sourceClass.equals(Data.class)) {
final String resource = ConvertersTestUtils.getTestResource(ConvertersTestUtils.class, resourcePath);
final Data complex = ConvertersTestUtils.createComplex(mimeType, encoding, schema, resource);
return converter.convert((SourceType) complex, param);
} else if (sourceClass.equals(Reference.class)) {
final URL resource = ConvertersTestUtils.class.getResource(resourcePath);
final Reference reference = ConvertersTestUtils.createReference("1.0.0", mimeType, encoding, schema, resource);
return converter.convert((SourceType) reference, param);
} else {
fail();
return null;
}
}
use of org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference in project geotoolkit by Geomatys.
the class ReferenceToGridCoverage2DConverterTest method testConversionBase64.
@Test
@org.junit.Ignore("Fails randomly because of GeoTIFF reader not found.")
public void testConversionBase64() throws UnconvertibleObjectException, IOException {
final WPSObjectConverter<Reference, GridCoverage> converter = WPSConverterRegistry.getInstance().getConverter(Reference.class, GridCoverage.class);
final URL coverageBase64 = ReferenceToRenderedImageConverterTest.class.getResource("/inputs/coverage_geotiff_base64");
assertNotNull(coverageBase64);
final Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put(AbstractReferenceInputConverter.IOTYPE, WPSIO.IOType.INPUT);
parameters.put(AbstractReferenceInputConverter.ENCODING, "base64");
final Reference reference = new Reference();
reference.setHref(coverageBase64.toString());
reference.setMimeType("image/x-geotiff");
reference.setEncoding("base64");
final GridCoverage convertedCvg = converter.convert(reference, parameters);
assertNotNull(convertedCvg);
final GridCoverage expectedCvg = ConvertersTestUtils.makeCoverage();
final Envelope convertedEnvelope = convertedCvg.getGridGeometry().getEnvelope();
final Envelope expectedEnvelope = expectedCvg.getGridGeometry().getEnvelope();
assertTrue(Utilities.equalsIgnoreMetadata(expectedEnvelope.getCoordinateReferenceSystem(), convertedEnvelope.getCoordinateReferenceSystem()));
assertTrue(expectedEnvelope.getMinimum(0) == convertedEnvelope.getMinimum(0));
assertTrue(expectedEnvelope.getMinimum(1) == convertedEnvelope.getMinimum(1));
assertTrue(expectedEnvelope.getMaximum(0) == convertedEnvelope.getMaximum(0));
assertTrue(expectedEnvelope.getMaximum(1) == convertedEnvelope.getMaximum(1));
Assert.assertRasterEquals(expectedCvg.render(null), convertedCvg.render(null));
}
Aggregations