/** * Checks if a string is a valid name of a component. * * @param name * the name to be validated * @param type * the type of component (used for error messages) * @param previousEntries * the previous entries of that component type (for uniqueness * check) * @throws IllegalStateException * if the name is invalid */ private static void checkName(final String name, final Class<?> type, final List<? extends ReferenceData> previousEntries) throws IllegalStateException { if (StringUtils.isNullOrEmpty(name)) { throw new IllegalStateException(type.getSimpleName() + " name cannot be null"); } for (final ReferenceData referenceData : previousEntries) { if (name.equals(referenceData.getName())) { throw new IllegalStateException(type.getSimpleName() + " name is not unique: " + name); } } }
result.setText(getNullText()); } else if (value instanceof ReferenceData) { result.setText(((ReferenceData) value).getName());
public void removeReferenceData(final TenantContext tenantContext, final ReferenceData referenceData) throws IllegalArgumentException { if (referenceData == null) { throw new IllegalArgumentException("Reference data can not be null"); } final JaxbConfigurationReader jaxbConfigurationAdaptor = new JaxbConfigurationReader(); final RepositoryFile configurationFile = tenantContext.getConfigurationFile(); final Configuration configuration = configurationFile.readFile(in -> { return jaxbConfigurationAdaptor.unmarshall(in); }); boolean found = false; final List<Object> referenceDataList = getReferenceDataListByType(configuration, referenceData); for (Iterator<Object> it = referenceDataList.iterator(); it.hasNext(); ) { final String candidateName = WriteUpdatedConfigurationFileAction.getComparableName(it.next()); if (referenceData.getName().equals(candidateName)) { it.remove(); found = true; break; } } if (!found) { throw new IllegalArgumentException("Could not find reference data with name '" + referenceData + "'"); } configurationFile.writeFile(out -> { jaxbConfigurationAdaptor.marshall(configuration, out); }); }