@Override public D save(D definition) { Assert.notNull(definition, "Definition may not be null"); if (repository.findOne(definition.getName()) != null) { throwDefinitionAlreadyExistsException(definition); } streamParser.parse(definition.getName(), definition.getDefinition()); return repository.save(definition); }
static final <D extends Definition> D getDefinition( List<D> definitions, String name, boolean ignoreCase) { for (D definition : definitions) { if ((ignoreCase && definition.getName().equalsIgnoreCase(name)) || (!ignoreCase && definition.getName().equals(name))) { return definition; } } return null; }
/** * Safely retrieve an attribute value. * * @param attrDef attribute definition of the attribute to retrieve * @param attrMgr attribute manager containing the attributes * @return value of the attribute * @throws CoreException if the attribute does not exist. */ private <T, A extends IAttribute<T, A, D>, D extends IAttributeDefinition<T, A, D>> T getAttributeValue(D attrDef, AttributeManager attrMgr) throws CoreException { IAttribute<T, A, D> attr = attrMgr.getAttribute(attrDef); if (attr == null) { throw new CoreException( new Status( IStatus.ERROR, RMCorePlugin.PLUGIN_ID, NLS.bind(Messages.AbstractToolRuntimeSystem_3, attrDef.getName()))); } return attr.getValue(); }
@Override public D save(D definition) { Assert.notNull(definition, "Definition may not be null"); String name = definition.getName(); String def = definition.getDefinition(); validateBeforeSave(name, def); List<ModuleDescriptor> moduleDescriptors = parser.parse(name, def, definitionKind); // todo: the result of parse() should already have correct (polymorphic) definitions List<ModuleDefinition> moduleDefinitions = createModuleDefinitions(moduleDescriptors); if (!moduleDefinitions.isEmpty()) { definition.setModuleDefinitions(moduleDefinitions); } D savedDefinition = repository.save(definition); return afterSave(savedDefinition); }
/** * Validates that all deployment properties (of the form "module.<modulename>.<key>" do indeed * reference module names that belong to the stream/job definition). */ private void validateDeploymentProperties(D definition, Map<String, String> properties) { List<ModuleDescriptor> modules = parser.parse(definition.getName(), definition.getDefinition(), definitionKind); Set<String> moduleLabels = new HashSet<String>(modules.size()); for (ModuleDescriptor md : modules) { moduleLabels.add(md.getModuleLabel()); } for (Map.Entry<String, String> pair : properties.entrySet()) { Matcher matcher = DEPLOYMENT_PROPERTY_PATTERN.matcher(pair.getKey()); Assert.isTrue( matcher.matches(), String.format("'%s' does not match '%s'", pair.getKey(), DEPLOYMENT_PROPERTY_PATTERN)); String moduleName = matcher.group(1); Assert.isTrue( "*".equals(moduleName) || moduleLabels.contains(moduleName), String.format( "'%s' refers to a module that is not in the list: %s", pair.getKey(), moduleLabels)); } }
protected void throwDefinitionAlreadyExistsException(D definition) { throw new DefinitionAlreadyExistsException( definition.getName(), String.format("There is already a %s named '%%s'", definitionKind)); }
@Override public void deleteAll() { for (D d : findAll()) { delete(d.getName()); } }