Search in sources :

Example 41 with EUnexpected

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();
    }
}
Also used : EUnexpected(com.accenture.trac.common.exception.EUnexpected)

Example 42 with 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();
}
Also used : LocalDateTime(java.time.LocalDateTime) ByteString(com.google.protobuf.ByteString) EUnexpected(com.accenture.trac.common.exception.EUnexpected) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Example 43 with 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();
    }
}
Also used : EUnexpected(com.accenture.trac.common.exception.EUnexpected)

Example 44 with 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);
}
Also used : EUnexpected(com.accenture.trac.common.exception.EUnexpected)

Aggregations

EUnexpected (com.accenture.trac.common.exception.EUnexpected)44 IOException (java.io.IOException)8 EDataCorruption (com.accenture.trac.common.exception.EDataCorruption)4 ArrayList (java.util.ArrayList)3 ECacheTicket (com.accenture.trac.common.exception.ECacheTicket)2 EInputValidation (com.accenture.trac.common.exception.EInputValidation)2 ByteSeekableChannel (com.accenture.trac.common.util.ByteSeekableChannel)2 Http1to2Framing (com.accenture.trac.gateway.proxy.http.Http1to2Framing)2 JacksonException (com.fasterxml.jackson.core.JacksonException)2 JsonToken (com.fasterxml.jackson.core.JsonToken)2 ByteString (com.google.protobuf.ByteString)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)2 MetadataBatchRequest (com.accenture.trac.api.MetadataBatchRequest)1 MetadataBatchResponse (com.accenture.trac.api.MetadataBatchResponse)1 MetadataWriteRequest (com.accenture.trac.api.MetadataWriteRequest)1 TrustedMetadataApiGrpc (com.accenture.trac.api.TrustedMetadataApiGrpc)1 EMetadataNotFound (com.accenture.trac.common.exception.EMetadataNotFound)1 EPluginNotAvailable (com.accenture.trac.common.exception.EPluginNotAvailable)1 EStartup (com.accenture.trac.common.exception.EStartup)1