public ConditionEngineResult createResult(Multimap<String, String> metadata) { //if the eval info and hash are not present, disregard them if (!metadata.containsKey(DocumentFields.EvaluationInformationBlob) || !metadata.containsKey(DocumentFields.MetadataHash)) { logger.debug("No previous evaluation info or corresponding hash supplied - starting evaluation from scratch."); return new ConditionEngineResult(); } //if there are more than 1 of the has fields, disregard them Collection<String> allBlobFields = metadata.get(DocumentFields.EvaluationInformationBlob); Collection<String> allHashFields = metadata.get(DocumentFields.MetadataHash); if (allBlobFields.size() != 1 || allHashFields.size() != 1) { logger.debug(String.format("Incorrect number of blob fields %d or condition fields %d found, ignoring.", allBlobFields.size(), allHashFields.size())); return new ConditionEngineResult(); } String blob = allBlobFields.stream().findFirst().get(); String hash = allHashFields.stream().findFirst().get(); return validateConditionEngineResult(blob, hash); }
public ConditionEngineResult createResultFromMetadata(Multimap<String, MetadataValue> metadata){ //if the eval info and hash are not present, disregard them if(!metadata.containsKey(DocumentFields.EvaluationInformationBlob) || !metadata.containsKey(DocumentFields.MetadataHash)){ logger.debug("No previous evaluation info or corresponding hash supplied - starting evaluation from scratch."); return new ConditionEngineResult(); } //if there are more than 1 of the has fields, disregard them Collection<MetadataValue> allBlobFields = metadata.get(DocumentFields.EvaluationInformationBlob); Collection<MetadataValue> allHashFields = metadata.get(DocumentFields.MetadataHash); if(allBlobFields.size() != 1 || allHashFields.size() != 1) { logger.debug(String.format("Incorrect number of blob fields %d or condition fields %d found, ignoring.", allBlobFields.size(), allHashFields.size())); return new ConditionEngineResult(); } MetadataValue blob = allBlobFields.stream().findFirst().get(); MetadataValue hash = allHashFields.stream().findFirst().get(); //deserialize the blob and validate with the hash, if all checks out then we're good. return validateConditionEngineResult(blob.getAsString(), hash.getAsString()); }