@Override public LocalDateTime getLastUpdated() { return catalogReader.getLastUpdated(); } }
@Override public DataType convertToEntityAttribute(String value) { return DataType.fromName(value); } }
private static void validateConstraints(boolean isRequestContext, Collection<Constraint> constraints, String name, String value, StringBuilder errors) { for (Constraint constraint : constraints) { constraintPlugins.validateConstraint(isRequestContext, constraint.getConstraintType().getName(), name, value, constraint.getValue(), errors); } } }
public Attribute convert(AttributeModel model) { Attribute attribute = new Attribute(); attribute.setName(model.getName()); attribute.setDisplayName(model.getDisplayName()); attribute.setDescription(model.getDescription()); attribute.setAliases(model.getAliases()); attribute.setId(model.getId()); attribute.setCatalogId(model.getCatalogId()); attribute.setIndexed(model.isIndexed()); attribute.setSortable(model.isSortable()); attribute.setRequestContext(model.isRequestContext()); attribute.setRequired(model.isRequired()); attribute.setDataType(model.getDataType()); Set<ConstraintModel> constraintModels = model.getConstraints(); Set<Constraint> constraints = new HashSet<>(); if (constraintModels != null) { for (ConstraintModel constraintModel : constraintModels) { Constraint constraint = new Constraint(); constraint.setId(constraintModel.getId()); constraint.setConstraintType(ConstraintPlugins.getInstance().findByName(constraintModel.getConstraintType())); constraint.setValue(constraintModel.getValue()); constraints.add(constraint); } } attribute.setConstraints(constraints); return attribute; } }
private Map<String, Map<String, CatalogInfo>> initializeData(CatalogReader catalogReader) throws Exception { JsonFactory factory = new JsonFactory(); factory.enable(JsonParser.Feature.ALLOW_COMMENTS); ObjectMapper mapper = new ObjectMapper(factory); String catalog = catalogReader.readCatalog(); catalogData = mapper.readValue(catalog, CatalogData.class); if (catalogData.getAttributes() != null) { for (Attribute attr : catalogData.getAttributes()) { if (attr.isRequestContext()) { requestContextAttributes.put(attr.getName(), attr); } Map<String, Attribute> attrMap = attributeMap.get(attr.getCatalogId()); if (attrMap == null) { attrMap = new HashMap<>(); attributeMap.put(attr.getCatalogId(), attrMap); } attrMap.put(attr.getName(), attr); } } Map<String, Map<String, CatalogInfo>> map = new HashMap<>(); map.put(DEFAULT_CATALOG, new HashMap<>()); for (Event event : catalogData.getEvents()) { addEntry(map, event); } return map; }
sb.append("null"); } else { sb.append(dataType.getTypeName()); sb.append(" "); sb.append("name=\"").append(constraint.getConstraintType().getName()).append("\""); sb.append("value=\"").append(constraint.getValue()).append("\"");
@Override public Map<String, Attribute> getAttributes(String eventName, String catalogId) { Event event = getEvent(eventName, catalogId); if (event == null) { logger.warn("The event named {} could not be found in catalog {}", eventName, catalogId); return null; } List<EventAttribute> eventAttributes = event.getAttributes() == null ? emptyList() : event.getAttributes(); Map<String, Attribute> attributes = new HashMap<>(eventAttributes.size()); for (EventAttribute eventAttribute : eventAttributes) { Attribute attr = getAttribute(eventAttribute.getName(), event.getCatalogId()); if (attr != null) { attributes.put(attr.getName(), attr); } } return attributes; }
public Event convert(EventModel model) { Event event = new Event(); event.setName(model.getName()); event.setDisplayName(model.getDisplayName()); event.setDescription(model.getDescription()); event.setAliases(model.getAliases()); event.setId(model.getId()); event.setCatalogId(model.getCatalogId()); List<EventAttribute> attributes = new ArrayList<>(); if (model.getAttributes() != null) { for (EventAttributeModel eventAttributeModel : model.getAttributes()) { EventAttribute eventAttribute = new EventAttribute(); eventAttribute.setName(eventAttributeModel.getAttribute().getName()); eventAttribute.setRequired(eventAttributeModel.isRequired()); attributes.add(eventAttribute); } } event.setAttributes(attributes); return event; } }
void appendConstraint(Constraint constraint, StringBuilder buffer) { ConstraintType type = constraint.getConstraintType(); // Add the escapes since they have been removed when converting the original data to a Java Strinng. They need to // be added back for use in the Constraint declaration. buffer.append(String.format(CONSTRAINT, type.getName(), constraint.getValue().replace("\\", "\\\\"))); } }
public void init() { catalogData = catalogReader.read(); for (Attribute attribute : catalogData.getAttributes()) { attributes.put(attribute.getName(), attribute); } }
public Product convert(ProductModel productModel) { Product product = new Product(); product.setId(productModel.getId()); product.setName(productModel.getName()); product.setDisplayName(productModel.getDisplayName()); product.setDescription(productModel.getDescription()); product.setCatalogId(productModel.getCatalogId()); List<String> events = new ArrayList<>(productModel.getEvents().size()); for (EventModel event : productModel.getEvents()) { events.add(event.getName()); } product.setEvents(events); return product; } }
public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{\"name\" : \"").append(name).append("\", \"displayName\" : \"").append(displayName).append("\""); sb.append(", \"description\" : \"").append(description).append("\", \"attributes\" : ["); boolean first = true; for (EventAttribute attribute : attributes) { if (!first) { sb.append(", "); } else { first = false; } sb.append("{\"name\" : \"").append(attribute.getName()).append("\", \"required\" : ").append(attribute.isRequired()).append("}"); } sb.append("]}"); return sb.toString(); } }
@Override public String convertToDatabaseColumn(DataType value) { return value != null ? value.getTypeName() : null; }
@Override public Category getCategory(String name) { if (catalogData.getCategories() != null) { return catalogData.getCategories().stream().filter(c -> c.getName().equals(name)).findFirst().orElse(null); } return null; }
@Override public void serialize(ConstraintType constraintType, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("name", constraintType.getName()); jsonGenerator.writeEndObject(); } }
@Override public Product getProduct(String name) { if (catalogData.getProducts() != null) { return catalogData.getProducts().stream().filter(p -> p.getName().equals(name)).findFirst().orElse(null); } return null; }
@Override public void serializeAsField(Object pojo, JsonGenerator jgen, SerializerProvider provider, PropertyWriter writer) throws Exception { if (writer.getName().equals("catalogId") && DEFAULT_CATALOG.equals(((Event)pojo).getCatalogId())) { return; } super.serializeAsField(pojo, jgen, provider, writer); } }
public static DataType fromName(String typeName) { for (DataType dataType: DataType.values()) { if (dataType.typeName.equalsIgnoreCase(typeName)) { return dataType; } } throw new IllegalArgumentException("Unknown data type: " + typeName); }
public void validateConstraint(boolean isRequestContext, String constraint, String name, String value, String constraintValue, StringBuilder errors) { ConstraintType constraintType = constraintMap.get(constraint.toLowerCase(Locale.US)); if (constraintType == null) { if (errors.length() > 0) { errors.append("\n"); } errors.append("Unable to locate constraint type ").append(constraint); if (isRequestContext) { errors.append(" for ThreadContext key "); } else { errors.append(" for key "); } errors.append(name); return; } constraintType.validate(isRequestContext, name, value, constraintValue, errors); }