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 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; } }
if (event.getAttributes() != null) { for (EventAttribute eventAttribute : event.getAttributes()) { String name = eventAttribute.getName(); Attribute attribute = getAttribute(name, event.getCatalogId()); if (attribute != null) {
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 (eventAttributes != null) { for (EventAttribute eventAttribute : eventAttributes) { Attribute attribute = attributes.get(eventAttribute.getName()); if (attribute == null) { LOGGER.error("Unable to locate attribute name {}", eventAttribute.getName()); errors = true; continue; String name = eventAttribute.getName(); if (name.startsWith(REQCTX)) { name = name.substring(REQCTX.length()); Set<Constraint> constraints = attribute.getConstraints(); boolean first = true; if (attribute.isRequired() || eventAttribute.isRequired()) { anyRequired = true; buffer.append(REQUIRED); final String attrName = name; if (event.getAttributes() != null) { Optional<EventAttribute> optional = event.getAttributes().stream().filter(a -> attrName.equals(a.getName())).findFirst(); if (optional.isPresent()) { isRequired = optional.get().isRequired();
if (event.getAttributes() != null) { for (EventAttribute eventAttribute : eventAttributes) { EventAttributeModel eventAttributeModel = model.getAttribute(eventAttribute.getName()); if (eventAttributeModel != null) { eventAttributeModel.setRequired(eventAttribute != null ? eventAttribute.isRequired() : null); } else { Optional<AttributeModel> optional = getAttribute(event.getCatalogId(), eventAttribute.getName()); if (optional.isPresent()) { eventAttributeModel = new EventAttributeModel(); if (eventAttribute != null) { eventAttributeModel.setRequired(eventAttribute.isRequired()); eventAttributeModels.add(eventAttributeModel); } else { throw new CatalogModificationException("No catalog entry for " + eventAttribute.getName()); eventAttributeModels.removeIf(a -> eventAttributes.stream().noneMatch(b -> b.getName().equals(a.getAttribute().getName()))); model.setAttributes(eventAttributeModels); return LOGGER.traceExit(model);