use of uk.gov.pay.products.util.ProductType in project pay-products by alphagov.
the class Product method from.
public static Product from(JsonNode jsonPayload) {
String externalId = (jsonPayload.get(FIELD_EXTERNAL_ID) != null) ? jsonPayload.get(FIELD_EXTERNAL_ID).asText() : randomUuid();
String payApiToken = (jsonPayload.get(FIELD_PAY_API_TOKEN) != null) ? jsonPayload.get(FIELD_PAY_API_TOKEN).asText() : null;
String name = (jsonPayload.get(FIELD_NAME) != null) ? jsonPayload.get(FIELD_NAME).asText() : null;
Long price = (jsonPayload.get(FIELD_PRICE) != null) ? jsonPayload.get(FIELD_PRICE).asLong() : null;
Integer gatewayAccountId = (jsonPayload.get(FIELD_GATEWAY_ACCOUNT_ID) != null ? jsonPayload.get(FIELD_GATEWAY_ACCOUNT_ID).asInt() : null);
String description = (jsonPayload.get(FIELD_DESCRIPTION) != null) ? jsonPayload.get(FIELD_DESCRIPTION).asText() : null;
ProductType type = (jsonPayload.get(FIELD_TYPE) != null) ? ProductType.valueOf(jsonPayload.get(FIELD_TYPE).asText()) : null;
String returnUrl = (jsonPayload.get(FIELD_RETURN_URL) != null) ? jsonPayload.get(FIELD_RETURN_URL).asText() : null;
String serviceNamePath = (jsonPayload.get(FIELD_SERVICE_NAME_PATH) != null) ? jsonPayload.get(FIELD_SERVICE_NAME_PATH).asText() : null;
String productNamePath = (jsonPayload.get(FIELD_PRODUCT_NAME_PATH) != null) ? jsonPayload.get(FIELD_PRODUCT_NAME_PATH).asText() : null;
Boolean referenceEnabled = (jsonPayload.get(FIELD_REFERENCE_ENABLED) != null) && jsonPayload.get(FIELD_REFERENCE_ENABLED).asBoolean();
String referenceLabel = (jsonPayload.get(FIELD_REFERENCE_LABEL) != null) ? jsonPayload.get(FIELD_REFERENCE_LABEL).asText() : null;
String referenceHint = (jsonPayload.get(FIELD_REFERENCE_HINT) != null) ? jsonPayload.get(FIELD_REFERENCE_HINT).asText() : null;
SupportedLanguage language = Optional.ofNullable(jsonPayload.get(FIELD_LANGUAGE)).map(JsonNode::asText).map(SupportedLanguage::fromIso639AlphaTwoCode).orElse(SupportedLanguage.ENGLISH);
List<ProductMetadata> metadataList = extractMetadata(jsonPayload, FIELD_METADATA);
return new Product(externalId, name, description, payApiToken, price, ProductStatus.ACTIVE, gatewayAccountId, type, returnUrl, serviceNamePath, productNamePath, referenceEnabled, referenceLabel, referenceHint, language, false, metadataList);
}
Aggregations