Search in sources :

Example 1 with HashType

use of org.finos.legend.pure.runtime.java.shared.hash.HashType in project legend-pure by finos.

the class Hash method execute.

@Override
public CoreInstance execute(ListIterable<? extends CoreInstance> params, Stack<MutableMap<String, CoreInstance>> resolvedTypeParameters, Stack<MutableMap<String, CoreInstance>> resolvedMultiplicityParameters, VariableContext variableContext, CoreInstance functionExpressionToUseInStack, Profiler profiler, InstantiationContext instantiationContext, ExecutionSupport executionSupport, Context context, ProcessorSupport processorSupport) throws PureExecutionException {
    // Parameter 0: text
    String text = PrimitiveUtilities.getStringValue(Instance.getValueForMetaPropertyToOneResolved(params.get(0), M3Properties.values, processorSupport));
    // Parameter 1: hashType
    CoreInstance enumeration = Instance.getValueForMetaPropertyToOneResolved(params.get(1), M3Properties.values, processorSupport);
    String enumName = enumeration.getName();
    HashType hashType = HashType.valueOf(enumName);
    try {
        String hashResult = HashingUtil.hash(text, hashType);
        CoreInstance result = this.modelRepository.newStringCoreInstance(hashResult);
        return ValueSpecificationBootstrap.wrapValueSpecification(result, true, processorSupport);
    } catch (Exception e) {
        throw new PureExecutionException(functionExpressionToUseInStack.getSourceInformation(), "Error occurred in hashing: " + e.getMessage(), e);
    }
}
Also used : HashType(org.finos.legend.pure.runtime.java.shared.hash.HashType) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException)

Example 2 with HashType

use of org.finos.legend.pure.runtime.java.shared.hash.HashType in project legend-pure by finos.

the class Pure method hash.

public static String hash(String text, Object hashTypeObject) {
    Enum hashTypeEnum = (Enum) hashTypeObject;
    HashType hashType = HashType.valueOf(hashTypeEnum._name());
    return HashingUtil.hash(text, hashType);
}
Also used : Enum(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum) HashType(org.finos.legend.pure.runtime.java.shared.hash.HashType)

Aggregations

HashType (org.finos.legend.pure.runtime.java.shared.hash.HashType)2 Enum (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum)1 PureExecutionException (org.finos.legend.pure.m3.exception.PureExecutionException)1 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)1