private static String errorMessage(BrooklynObject object, Iterable<ConfigKey<?>> violations) { StringBuilder message = new StringBuilder("Error configuring ") .append(object.getDisplayName()) .append(": ["); Iterator<ConfigKey<?>> it = violations.iterator(); while (it.hasNext()) { ConfigKey<?> config = it.next(); message.append(config.getName()) .append(":") .append(config.getConstraint()); if (it.hasNext()) { message.append(", "); } } return message.append("]").toString(); }
@Override public boolean apply(String input, BrooklynObject context) { return context != null && context.getDisplayName().equals(input); } }
private static void populateBrooklynObjectMementoBuilder(BrooklynObject instance, AbstractMemento.Builder<?> builder) { if (Proxy.isProxyClass(instance.getClass())) { throw new IllegalStateException("Attempt to create memento from proxy "+instance+" (would fail with wrong type)"); } OsgiClassPrefixer prefixer = new OsgiClassPrefixer(); Optional<String> typePrefix = prefixer.getPrefix(instance.getClass()); builder.id = instance.getId(); builder.displayName = instance.getDisplayName(); builder.catalogItemId = instance.getCatalogItemId(); builder.searchPath = instance.getCatalogItemIdSearchPath(); builder.type = (typePrefix.isPresent() ? typePrefix.get() : "") + instance.getClass().getName(); builder.typeClass = instance.getClass(); if (instance instanceof EntityAdjunct) { builder.uniqueTag = ((EntityAdjunct)instance).getUniqueTag(); } for (Object tag : instance.tags().getTags()) { builder.tags.add(tag); } // CatalogItems return empty support, so this is safe even through they don't support relations for (RelationshipType<?,? extends BrooklynObject> relationship: instance.relations().getRelationshipTypes()) { @SuppressWarnings({ "unchecked", "rawtypes" }) Set relations = instance.relations().getRelations((RelationshipType)relationship); Set<String> relationIds = Sets.newLinkedHashSet(); for (Object r: relations) relationIds.add( ((BrooklynObject)r).getId() ); builder.relations.put(relationship.getRelationshipTypeName(), relationIds); } }
@Nonnull static String getDisplayNameOrName(HasName o1) { String n1 = null; if (o1 instanceof BrooklynObject) n1 = ((BrooklynObject)o1).getDisplayName(); if (Strings.isEmpty(n1) && o1 instanceof HasConfig && ((HasConfig)o1).getConfig()!=null) n1 = Strings.toString(((HasConfig)o1).getConfig().get("displayName")); // prefer display name if set if (Strings.isEmpty(n1)) n1 = o1.getName(); if (n1==null) { // put last return "~~~"; } return n1; }
if (obj!=null) { contextName = obj.getCatalogItemId(); if (Strings.isBlank(contextName)) contextName= obj.getDisplayName();