public static BasicPolicyMemento.Builder newPolicyMementoBuilder(Policy policy) { BasicPolicyMemento.Builder builder = BasicPolicyMemento.builder(); builder.type = policy.getClass().getName(); builder.id = policy.getId(); builder.displayName = policy.getName(); builder.flags.putAll(FlagUtils.getFieldsWithFlagsExcludingModifiers(policy, Modifier.STATIC ^ Modifier.TRANSIENT)); return builder; } }
protected PolicySummary(Entity entity, Policy policy) { this.id = policy.getId(); this.name = policy.getName(); this.state = Policies.getPolicyStatus(policy); String applicationUri = "/v1/applications/" + entity.getApplicationId(); String entityUri = applicationUri + "/entities/" + entity.getId(); this.links = ImmutableMap.<String, URI>builder() .put("self", URI.create(entityUri + "/policies/" + policy.getId())) .put("config", URI.create(entityUri + "/policies/" + policy.getId() + "/config")) .put("start", URI.create(entityUri + "/policies/" + policy.getId() + "/start")) .put("stop", URI.create(entityUri + "/policies/" + policy.getId() + "/stop")) .put("destroy", URI.create(entityUri + "/policies/" + policy.getId() + "/destroy")) .put("application", URI.create(applicationUri)) .put("entity", URI.create(entityUri)) .build(); }
public static PolicySummary policySummary(Entity entity, Policy policy) { String applicationUri = "/v1/applications/" + entity.getApplicationId(); String entityUri = applicationUri + "/entities/" + entity.getId(); Map<String, URI> links = ImmutableMap.<String, URI>builder() .put("self", URI.create(entityUri + "/policies/" + policy.getId())) .put("config", URI.create(entityUri + "/policies/" + policy.getId() + "/config")) .put("start", URI.create(entityUri + "/policies/" + policy.getId() + "/start")) .put("stop", URI.create(entityUri + "/policies/" + policy.getId() + "/stop")) .put("destroy", URI.create(entityUri + "/policies/" + policy.getId() + "/destroy")) .put("application", URI.create(applicationUri)) .put("entity", URI.create(entityUri)) .build(); return new PolicySummary(policy.getId(), policy.getName(), ApplicationTransformer.statusFromLifecycle(Policies.getPolicyStatus(policy)), links); }
/** finds the policy indicated by the given ID or name. * @see {@link getPolicy(String,String,String)}. * <p> * * @throws 404 or 412 (unless input is null in which case output is null) */ public Policy getPolicy(Entity entity, String policy) { if (policy==null) return null; for (Policy p: entity.getPolicies()) { if (policy.equals(p.getId())) return p; } for (Policy p: entity.getPolicies()) { if (policy.equals(p.getName())) return p; } throw WebResourceUtils.notFound("Cannot find policy '%s' in entity '%s'", policy, entity); }
/** finds the policy indicated by the given ID or name. * @see {@link getPolicy(String,String,String)}. * <p> * * @throws 404 or 412 (unless input is null in which case output is null) */ public Policy getPolicy(Entity entity, String policy) { if (policy==null) return null; for (Policy p: entity.getPolicies()) { if (policy.equals(p.getId())) return p; } for (Policy p: entity.getPolicies()) { if (policy.equals(p.getName())) return p; } throw WebResourceUtils.notFound("Cannot find policy '%s' in entity '%s'", policy, entity); }
public PolicyDescriptor(Policy policy) { this.id = policy.getId(); this.type = policy.getPolicyType().getName(); this.name = policy.getName(); } public String getId() {