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; }
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; } }
public AttributeModel convert(Attribute attribute) { LOGGER.traceEntry(attribute.getName()); AttributeModel model; if (attribute.getId() != null) { model = attributeService.getAttribute(attribute.getId()).orElseGet(AttributeModel::new); } else { model = new AttributeModel(); model.setName(attribute.getName()); model.setAliases(attribute.getAliases()); model.setDescription(attribute.getDescription()); model.setDisplayName(attribute.getDisplayName()); model.setDataType(attribute.getDataType()); model.setId(attribute.getId()); model.setCatalogId(attribute.getCatalogId()); model.setIndexed(attribute.isIndexed()); model.setRequestContext(attribute.isRequestContext()); model.setRequired(attribute.isRequired()); model.setSortable(attribute.isSortable()); model.setExamples(attribute.getExamples()); Set<ConstraintModel> constraintModels = model.getConstraints() != null ? model.getConstraints() : new HashSet<>(); Map<Long, ConstraintModel> constraintMap = constraintModels.stream().collect(Collectors.toMap(ConstraintModel::getId, Function.identity())); if (attribute.getConstraints() != null) { constraintModels.removeIf(a -> attribute.getConstraints().stream().noneMatch(b -> b.getId().equals(a.getId()))); for (Constraint constraint : attribute.getConstraints()) { ConstraintModel constraintModel; if (constraint.getId() != null) {
boolean anyConstraints = false; for (Attribute attribute : attributes.values()) { if (attribute.isRequestContext()) { String name = attribute.getName(); if (name.startsWith(REQCTX)) { name = name.substring(REQCTX.length()); requestContextIsRequired.put(name, attribute.isRequired()); if (attribute.isRequestContext() && attribute.isRequired()) { String name = eventAttribute.getName(); if (name.startsWith(REQCTX)) { String name = attribute.getName(); String type = attribute.getDataType().getTypeName(); if (!attribute.isRequestContext() && attribute.getDataType().getImportClass() != null) { if (!importedTypes.containsKey(attribute.getDataType().getTypeName())) { importedTypes.put(attribute.getDataType().getTypeName(), attribute.getDataType().getImportClass()); definition.addParameter(new Parameter(name, type, attribute.getDescription())); definition.setInterface(true); definition.setVisability("public"); definition.setJavadocComments(attribute.getDisplayName() + " : " + attribute.getDescription()); Set<Constraint> constraints = attribute.getConstraints(); boolean first = true;
for (EventAttribute eventAttribute : eventAttributes) { Attribute attr = catalogManager.getAttribute(eventAttribute.getName(), event.getCatalogId()); if ((!attr.isRequestContext() && (attr.isRequired()) || (eventAttribute.isRequired() != null && eventAttribute.isRequired()))) { String name = attr.getName(); if (!attributes.containsKey(name)) { if (missingAttributes.length() > 0) { if (attr.getConstraints() != null && attr.getConstraints().size() > 0) { validateConstraints(false, attr.getConstraints(), name, attributes.get(name), errors); Attribute attribute = entry.getValue(); String attr = entry.getKey(); if (attribute.isRequired() && !ThreadContext.containsKey(attr)) { if (errors.length() > 0) { errors.append(", "); continue; Set<Constraint> constraintList = attribute.getConstraints(); if (constraintList != null && constraintList.size() > 0) { validateConstraints(true, constraintList, entry.getKey(), ThreadContext.get(entry.getKey()), errors);
name = name.replaceAll("/", ""); if (attribute.isRequestContext()) { if (attribute.isRequired()) { if (name.startsWith(REQCTX)) { name = name.substring(REQCTX.length());
public void init() { catalogData = catalogReader.read(); for (Attribute attribute : catalogData.getAttributes()) { attributes.put(attribute.getName(), attribute); } }
@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; }