use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class RestApiTranslator method extractInt.
private TRequest.Builder extractInt(Function<URI, String> rawValueExtractor, Function<TRequest.Builder, Message.Builder> subFieldMapper, Descriptors.FieldDescriptor targetField, URI uri, TRequest.Builder request) {
var rawValue = rawValueExtractor.apply(uri);
var stringValue = URLDecoder.decode(rawValue, StandardCharsets.US_ASCII);
try {
var intValue = Integer.parseInt(stringValue);
var subField = subFieldMapper.apply(request);
subField.setField(targetField, intValue);
return request;
} catch (NumberFormatException e) {
// Invalid values should not make it past the router matcher
throw new EUnexpected();
}
}
use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class DataApiTestHelpers method decodeJavaObject.
public static Object decodeJavaObject(BasicType fieldType, Object rawObject) {
switch(fieldType) {
case BOOLEAN:
if (rawObject instanceof Boolean)
return rawObject;
if (rawObject instanceof String)
return Boolean.valueOf(rawObject.toString());
throw new EUnexpected();
case INTEGER:
if (rawObject instanceof Long)
return rawObject;
if (rawObject instanceof Integer)
return (long) (int) rawObject;
if (rawObject instanceof Short)
return (long) (short) rawObject;
if (rawObject instanceof Byte)
return (long) (byte) rawObject;
if (rawObject instanceof String)
return Long.parseLong(rawObject.toString());
throw new EUnexpected();
case FLOAT:
if (rawObject instanceof Double)
return rawObject;
if (rawObject instanceof Float)
return rawObject;
if (rawObject instanceof String)
return Double.parseDouble(rawObject.toString());
throw new EUnexpected();
case DECIMAL:
if (rawObject instanceof BigDecimal)
return rawObject;
if (rawObject instanceof String)
return new BigDecimal(rawObject.toString());
break;
case STRING:
return rawObject.toString();
case DATE:
if (rawObject instanceof LocalDate)
return rawObject;
if (rawObject instanceof String)
return LocalDate.parse(rawObject.toString());
break;
case DATETIME:
if (rawObject instanceof LocalDateTime)
return rawObject;
if (rawObject instanceof String)
return LocalDateTime.parse(rawObject.toString(), MetadataCodec.ISO_DATETIME_NO_ZONE_FORMAT);
break;
default:
System.out.println(fieldType);
System.out.println(rawObject.getClass());
throw new EUnexpected();
}
System.out.println(fieldType);
System.out.println(rawObject.getClass());
throw new EUnexpected();
}
use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class JobState method serialize.
public static <T extends Serializable> byte[] serialize(T obj) {
try (var bos = new ByteArrayOutputStream();
var oos = new ObjectOutputStream(bos)) {
oos.writeObject(obj);
oos.flush();
return bos.toByteArray();
} catch (IOException e) {
// TODO
throw new EUnexpected();
}
}
use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class ImportModelJob method buildResultMetadata.
@Override
public List<MetadataWriteRequest> buildResultMetadata(String tenant, JobConfig jobConfig, JobResult jobResult) {
var modelObjMaybe = jobResult.getResultsMap().values().stream().findFirst();
if (modelObjMaybe.isEmpty())
throw new EUnexpected();
var modelObj = modelObjMaybe.get();
var modelDef = modelObj.getModel();
var controlledAttrs = List.of(TagUpdate.newBuilder().setAttrName(TRAC_MODEL_LANGUAGE).setValue(encodeValue(modelDef.getLanguage())).build(), TagUpdate.newBuilder().setAttrName(TRAC_MODEL_REPOSITORY).setValue(encodeValue(modelDef.getRepository())).build(), TagUpdate.newBuilder().setAttrName(TRAC_MODEL_PATH).setValue(encodeValue(modelDef.getPath())).build(), TagUpdate.newBuilder().setAttrName(TRAC_MODEL_ENTRY_POINT).setValue(encodeValue(modelDef.getEntryPoint())).build(), TagUpdate.newBuilder().setAttrName(TRAC_MODEL_VERSION).setValue(encodeValue(modelDef.getVersion())).build());
var suppliedAttrs = jobConfig.getJob().getImportModel().getModelAttrsList();
var modelReq = MetadataWriteRequest.newBuilder().setTenant(tenant).setObjectType(ObjectType.MODEL).setDefinition(modelObj).addAllTagUpdates(controlledAttrs).addAllTagUpdates(suppliedAttrs).build();
return List.of(modelReq);
}
Aggregations