/** * parses a ContextId object from a Map-representation used in * {@link org.openengsb.core.api.persistence.ConfigPersistenceService} */ public static ContextId fromMetaData(Map<String, String> metaData) { return new ContextId(metaData.get(META_KEY_ID)); }
@Override public String toString() { return "Context: " + getId(); }
@Override public List<String> getAvailableContexts() { List<ContextConfiguration> availableContextConfigurations = getContextConfigurationsOrEmptyOnError(ContextId.getContextIdWildCard()); List<String> availableContexts = new ArrayList<String>(); for (ContextConfiguration configuration : availableContextConfigurations) { availableContexts.add(ContextId.fromMetaData(configuration.getMetaData()).getId()); } return availableContexts; }
private Context getContextById(String currentContextId) { ContextId contextId = new ContextId(currentContextId); List<ContextConfiguration> contexts = getContextConfigurationsOrEmptyOnError(contextId.toMetaData()); if (contexts.isEmpty()) { return null; } return contexts.get(0).toContext(); }
public Context toContext() { ContextId contextId = ContextId.fromMetaData(getMetaData()); Context c = new Context(); c.setId(contextId.getId()); return c; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() == obj.getClass()) { ContextId other = (ContextId) obj; return equals(other); } if (Map.class.isInstance(obj)) { Map<?, ?> metadata = (Map<?, ?>) obj; return toMetaData().equals(metadata); } if (obj instanceof String) { return toString().equals(obj); } return false; }
@Override public void deleteContext(String contextId) { LOGGER.debug("deleting context {}", contextId); try { getConfigPersistenceService().remove(new ContextId(contextId).toMetaData()); } catch (PersistenceException e) { throw new RuntimeException(e); } }
public Context toContext() { ContextId contextId = ContextId.fromMetaData(this.getMetaData()); Context c = new Context(); c.setId(contextId.getId()); return c; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() == obj.getClass()) { ContextId other = (ContextId) obj; return equals(other); } if (Map.class.isInstance(obj)) { Map<?, ?> metadata = (Map<?, ?>) obj; return toMetaData().equals(metadata); } if (obj instanceof String) { return toString().equals(obj); } return false; }
@Override public void createContext(String contextId) { LOGGER.debug("Creating context %s", contextId); ContextConfiguration contextConfiguration = new ContextConfiguration(new ContextId(contextId).toMetaData(), null); try { getConfigPersistenceService().persist(contextConfiguration); } catch (InvalidConfigurationException e) { LOGGER.error("Error storing context " + contextId + ": Invalid configuration", e); } catch (PersistenceException e) { LOGGER.error("Error storing context " + contextId + ": Persistence error", e); } }
/** * parses a ContextId object from a Map-representation used in * {@link org.openengsb.core.api.persistence.ConfigPersistenceService} */ public static ContextId fromMetaData(Map<String, String> metaData) { return new ContextId(metaData.get(META_KEY_ID)); }
@Override public String toString() { return "Context: " + getId(); }