Java Code Examples for org.apache.brooklyn.api.entity.Entity#getDisplayName()

The following examples show how to use org.apache.brooklyn.api.entity.Entity#getDisplayName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskTransformer.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static LinkWithMetadata asLink(Task<?> t, UriBuilder ub) {
    if (t==null) return null;
    MutableMap<String,Object> data = new MutableMap<String,Object>();
    data.put("id", t.getId());
    if (t.getDisplayName()!=null) data.put("taskName", t.getDisplayName());
    Entity entity = BrooklynTaskTags.getContextEntity(t);
    if (entity!=null) {
        data.put("entityId", entity.getId());
        if (entity.getDisplayName()!=null) data.put("entityDisplayName", entity.getDisplayName());
    }
    URI taskUri = serviceUriBuilder(ub, ActivityApi.class, "get").build(t.getId());
    return new LinkWithMetadata(taskUri.toString(), data);
}
 
Example 2
Source File: DynamicFabricImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected Entity addCluster(Location location) {
    String locationName = elvis(location.getDisplayName(), location.getDisplayName(), null);
    Map creation = Maps.newLinkedHashMap();
    creation.putAll(getCustomChildFlags());
    if (groovyTruth(getDisplayNamePrefix()) || groovyTruth(getDisplayNameSuffix())) {
        String displayName = "" + elvis(getDisplayNamePrefix(), "") + elvis(locationName, "unnamed") + elvis(getDisplayNameSuffix(),"");
        creation.put("displayName", displayName);
    }
    logger.info("Creating entity in fabric {} at {}{}", new Object[] {this, location, 
            (creation!=null && !creation.isEmpty() ? ", properties "+creation : "") });

    Entity entity = createCluster(location, creation);
    
    if (locationName != null) {
        if (entity.getDisplayName()==null)
            entity.setDisplayName(entity.getEntityType().getSimpleName() +" ("+locationName+")");
        else if (!entity.getDisplayName().contains(locationName)) 
            entity.setDisplayName(entity.getDisplayName() +" ("+locationName+")");
    }
    if (entity.getParent()==null) entity.setParent(this);
    
    // Continue to call manage(), because some uses of NodeFactory (in tests) still instantiate the
    // entity via its constructor
    Entities.manage(entity);
    
    addMember(entity);
    
    return entity;
}
 
Example 3
Source File: EntityFunctions.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** @deprecated since 0.9.0 kept only to allow conversion of non-static inner classes */
@SuppressWarnings("unused") @Deprecated 
private static Function<Entity, String> displayNameOld() {
    // TODO PERSISTENCE WORKAROUND
    class GetEntityDisplayName implements Function<Entity, String> {
        @Override public String apply(Entity input) {
            return (input == null) ? null : input.getDisplayName();
        }
    }
    return new GetEntityDisplayName();
}
 
Example 4
Source File: EntityTransformer.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public static EntitySummary entitySummary(Entity entity, UriBuilder ub) {
        URI applicationUri = serviceUriBuilder(ub, ApplicationApi.class, "get").build(entity.getApplicationId());
        URI entityUri = serviceUriBuilder(ub, EntityApi.class, "get").build(entity.getApplicationId(), entity.getId());
        ImmutableMap.Builder<String, URI> lb = ImmutableMap.<String, URI>builder()
                .put("self", entityUri);
        if (entity.getParent()!=null) {
            URI parentUri = serviceUriBuilder(ub, EntityApi.class, "get").build(entity.getApplicationId(), entity.getParent().getId());
            lb.put("parent", parentUri);
        }

//        UriBuilder urib = serviceUriBuilder(ub, EntityApi.class, "getChildren").build(entity.getApplicationId(), entity.getId());
        // TODO: change all these as well :S
        lb.put("application", applicationUri)
                .put("children", URI.create(entityUri + "/children"))
                .put("config", URI.create(entityUri + "/config"))
                .put("sensors", URI.create(entityUri + "/sensors"))
                .put("effectors", URI.create(entityUri + "/effectors"))
                .put("adjuncts", URI.create(entityUri + "/adjuncts"))
                .put("policies", URI.create(entityUri + "/policies"))
                .put("activities", URI.create(entityUri + "/activities"))
                .put("locations", URI.create(entityUri + "/locations"))
                .put("tags", URI.create(entityUri + "/tags"))
                .put("expunge", URI.create(entityUri + "/expunge"))
                .put("rename", URI.create(entityUri + "/name"))
                .put("spec", URI.create(entityUri + "/spec"))
            ;

        if (RegisteredTypes.getIconUrl(entity)!=null)
            lb.put("iconUrl", URI.create(entityUri + "/icon"));

        if (entity.getCatalogItemId() != null) {
            String versionedId = entity.getCatalogItemId();
            URI catalogUri;
            String symbolicName = CatalogUtils.getSymbolicNameFromVersionedId(versionedId);
            String version = CatalogUtils.getVersionFromVersionedId(versionedId);
            catalogUri = serviceUriBuilder(ub, CatalogApi.class, "getEntity").build(symbolicName, version);
            lb.put("catalog", catalogUri);
        }

        String type = entity.getEntityType().getName();
        return new EntitySummary(entity.getId(), entity.getDisplayName(), type, entity.getCatalogItemId(), lb.build());
    }
 
Example 5
Source File: ApplicationResource.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
/** depth 0 means no detail even at root; negative means infinite; positive means include details for that many levels 
 * (ie 1 means this entity but no details of descendants) */
private EntitySummary fromEntity(Entity entity, boolean includeTags, int detailDepth, List<String> extraSensorGlobs, List<String> extraConfigGlobs) {
    if (detailDepth==0) {
        return new EntitySummary(
            entity.getId(), 
            entity.getDisplayName(),
            entity.getEntityType().getName(),
            entity.getCatalogItemId(),
            MutableMap.of("self", EntityTransformer.entityUri(entity, ui.getBaseUriBuilder())) );
    }

    Boolean serviceUp = entity.getAttribute(Attributes.SERVICE_UP);

    Lifecycle serviceState = entity.getAttribute(Attributes.SERVICE_STATE_ACTUAL);

    String iconUrl = RegisteredTypes.getIconUrl(entity);
    if (iconUrl!=null) {
        if (brooklyn().isUrlServerSideAndSafe(iconUrl))
            // route to server if it is a server-side url
            iconUrl = EntityTransformer.entityUri(entity, ui.getBaseUriBuilder())+"/icon";
    }

    List<EntitySummary> children = Lists.newArrayList();
    if (!entity.getChildren().isEmpty()) {
        for (Entity child : entity.getChildren()) {
            if (Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, child)) {
                children.add(fromEntity(child, includeTags, detailDepth-1, extraSensorGlobs, extraConfigGlobs));
            }
        }
    }

    String parentId = null;
    if (entity.getParent()!= null) {
        parentId = entity.getParent().getId();
    }

    List<String> groupIds = Lists.newArrayList();
    if (!entity.groups().isEmpty()) {
        groupIds.addAll(entitiesIdAsArray(entity.groups()));
    }

    List<Map<String, String>> members = Lists.newArrayList();
    if (entity instanceof Group) {
        // use attribute instead of method in case it is read-only
        Collection<Entity> memberEntities = entity.getAttribute(AbstractGroup.GROUP_MEMBERS);
        if (memberEntities != null && !memberEntities.isEmpty())
            members.addAll(entitiesIdAndNameAsList(memberEntities));
    }

    EntityDetail result = new EntityDetail(
            entity.getApplicationId(),
            entity.getId(),
            parentId,
            entity.getDisplayName(),
            entity.getEntityType().getName(),
            serviceUp,
            serviceState,
            iconUrl,
            entity.getCatalogItemId(),
            children,
            groupIds,
            members,
            MutableMap.of("self", EntityTransformer.entityUri(entity, ui.getBaseUriBuilder())) );
    
    if (includeTags) {
        result.setExtraField("tags", resolving(MutableList.copyOf(entity.tags().getTags())).preferJson(true).resolve() );
    }
    result.setExtraField("creationTimeUtc", entity.getCreationTime());
    addSensorsByGlobs(result, entity, extraSensorGlobs);
    addConfigByGlobs(result, entity, extraConfigGlobs);
    
    return result;
}
 
Example 6
Source File: ServiceStateLogic.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
private String nameOfEntity(Entity entity) {
    String name = entity.getDisplayName();
    if (name.contains(entity.getId())) return name;
    else return name + " ("+entity.getId()+")";
}
 
Example 7
Source File: EntityPredicates.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Override
public boolean apply(@Nullable Entity input) {
    return (input != null && input.getDisplayName() != null) && input.getDisplayName().matches(regex);
}
 
Example 8
Source File: EntityFunctions.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Override public String apply(Entity input) {
    return (input == null) ? null : input.getDisplayName();
}