private static void validatePropertyNames(Bean bean) { Schema schema = bean.getSchema(); Set<String> schemaPropertyNames = schema.getPropertyNames(); for (String name : bean.getPropertyNames()) { if (!schemaPropertyNames.contains(name)) { throw Events.CFG110_PROP_NOT_EXIST_IN_SCHEMA(name); } } }
@Test public void test_set_empty_properties() { createThenGet(c1); Bean b = Bean.create(BeanId.create("c1", CHILD_SCHEMA_NAME)); admin.set(b); Bean result = admin.get(b.getId()).get(); assertThat(result.getPropertyNames().size(), is(0)); }
public JaxrsBean(Bean bean) { this.schemaName = bean.getId().getSchemaName(); this.id = bean.getId().getInstanceId(); for (String name : bean.getPropertyNames()) { List<String> values = bean.getValues(name); if (values == null || values.isEmpty()) { continue; } properties.put(name, values); } for (String name : bean.getReferenceNames()) { List<BeanId> refs = bean.getReferences(); if (refs == null || refs.isEmpty()) { continue; } List<String> values = new ArrayList<>(); for (BeanId id : refs) { values.add(id.getInstanceId()); } properties.put(name, values); } }
private void merge(List<Bean> sources, Bean mergeBean) { HashMap<BeanId, Bean> cache = new HashMap<>(); for (Bean source : sources) { for (String name : mergeBean.getPropertyNames()) { List<String> values = mergeBean.getValues(name); if (values == null || values.size() == 0) {
private void replace(Bean target, Bean replace) { if (target == null) { // bean did not exist in storage, create it. target = replace; } checkReferencesExist(replace, new ArrayList<Bean>()); for (String name : replace.getPropertyNames()) { List<String> values = replace.getValues(name); if (values == null || values.size() == 0) { // null/empty indicates a remove/reset-to-default op target.remove(name); } else { target.setProperty(name, replace.getValues(name)); } } for (String name : replace.getReferenceNames()) { List<BeanId> values = replace.getReference(name); if (values == null || values.size() == 0) { // null/empty indicates a remove/reset-to-default op target.remove(name); } else { target.setReferences(name, values); } } }
public static Bean copy(Bean bean) { if (bean == null) { return null; } Bean copy = Bean.create(bean.getId()); for (String property : bean.getPropertyNames()) { Collection<String> values = bean.getValues(property); if (values == null) { continue; } copy.setProperty(property, bean.getValues(property)); } for (String property : bean.getReferenceNames()) { List<BeanId> ids = bean.getReference(property); if (ids == null) { continue; } for (BeanId id : ids) { copy.addReference(property, BeanId.create(id.getInstanceId(), id.getSchemaName())); } } return copy; }
public static Bean copy(Bean bean) { if (bean == null) { return null; } Bean copy = Bean.create(bean.getId()); for (String property : bean.getPropertyNames()) { Collection<String> values = bean.getValues(property); if (values == null) { continue; } copy.setProperty(property, bean.getValues(property)); } for (String property : bean.getReferenceNames()) { List<BeanId> ids = bean.getReference(property); if (ids == null) { continue; } for (BeanId id : ids) { copy.addReference(property, BeanId.create(id.getInstanceId(), id.getSchemaName())); } } return copy; }