| | |
| | | import java.util.LinkedHashMap; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | import javax.naming.NamingException; |
| | |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.opends.server.types.ObjectClass; |
| | | import org.opends.server.types.OpenDsException; |
| | | import org.opends.server.types.SchemaFileElement; |
| | | import org.opends.server.util.LDIFReader; |
| | | import org.opends.server.util.LDIFWriter; |
| | | import org.opends.server.util.ServerConstants; |
| | | import org.opends.server.util.StaticUtils; |
| | | |
| | | import static org.opends.server.types.CommonSchemaElements.*; |
| | | |
| | | /** |
| | | * An abstract class used to re-factor some code between the different tasks |
| | | * that create elements in the schema. |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Set<String> getBackends() |
| | | { |
| | | return Collections.emptySet(); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean canLaunch(Task taskToBeLaunched, |
| | | Collection<LocalizableMessage> incompatibilityReasons) |
| | | { |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void runTask() |
| | | { |
| | | state = State.RUNNING; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public Type getType() |
| | | { |
| | | return Type.NEW_SCHEMA_ELEMENT; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public LocalizableMessage getTaskDescription() |
| | | { |
| | | if (attrsToAdd.size() == 1 && ocsToAdd.isEmpty()) |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected String getCommandLinePath() |
| | | { |
| | | return null; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected List<String> getCommandLineArguments() |
| | | { |
| | | return Collections.emptyList(); |
| | |
| | | addAttributeOnline(attr); |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | getProgressDialog().appendProgressHtml(Utilities.applyFont("<br><br>", |
| | |
| | | addObjectClassOnline(oc); |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | getProgressDialog().appendProgressHtml(Utilities.applyFont("<br><br>", |
| | |
| | | private void updateSchemaOffline() throws OpenDsException |
| | | { |
| | | // Group the changes in the same schema file. |
| | | LinkedHashMap<String, List<AttributeType>> hmAttrs = |
| | | new LinkedHashMap<String, List<AttributeType>>(); |
| | | for (AttributeType attr : attrsToAdd) |
| | | { |
| | | String fileName = getFileName(attr); |
| | | if (fileName == null) |
| | | { |
| | | fileName = ""; |
| | | } |
| | | List<AttributeType> attrs = hmAttrs.get(fileName); |
| | | if (attrs == null) |
| | | { |
| | | attrs = new ArrayList<AttributeType>(); |
| | | hmAttrs.put(fileName, attrs); |
| | | } |
| | | attrs.add(attr); |
| | | } |
| | | |
| | | LinkedHashMap<String, List<ObjectClass>> hmOcs = |
| | | new LinkedHashMap<String, List<ObjectClass>>(); |
| | | for (ObjectClass oc : ocsToAdd) |
| | | { |
| | | String fileName = getFileName(oc); |
| | | if (fileName == null) |
| | | { |
| | | fileName = ""; |
| | | } |
| | | List<ObjectClass> ocs = hmOcs.get(fileName); |
| | | if (ocs == null) |
| | | { |
| | | ocs = new ArrayList<ObjectClass>(); |
| | | hmOcs.put(fileName, ocs); |
| | | } |
| | | ocs.add(oc); |
| | | } |
| | | LinkedHashMap<String, List<AttributeType>> hmAttrs = copy(attrsToAdd); |
| | | LinkedHashMap<String, List<ObjectClass>> hmOcs = copy(ocsToAdd); |
| | | |
| | | LinkedHashSet<String> allFileNames = new LinkedHashSet<String>(); |
| | | allFileNames.addAll(hmAttrs.keySet()); |
| | | allFileNames.addAll(hmOcs.keySet()); |
| | | for (String fileName : allFileNames) |
| | | { |
| | | List<AttributeType> attrs = hmAttrs.get(fileName); |
| | | List<ObjectClass> ocs = hmOcs.get(fileName); |
| | | if (attrs == null) |
| | | { |
| | | attrs = Collections.emptyList(); |
| | | } |
| | | if (ocs == null) |
| | | { |
| | | ocs = Collections.emptyList(); |
| | | } |
| | | List<AttributeType> attrs = get(hmAttrs, fileName); |
| | | List<ObjectClass> ocs = get(hmOcs, fileName); |
| | | |
| | | if (fileName.equals("")) |
| | | { |
| | |
| | | updateSchemaOffline(fileName, attrs, ocs); |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | getProgressDialog().appendProgressHtml(Utilities.applyFont("<br><br>", |
| | |
| | | } |
| | | } |
| | | |
| | | private <T extends SchemaFileElement> List<T> get( |
| | | LinkedHashMap<String, List<T>> hmElems, String fileName) |
| | | { |
| | | List<T> elems = hmElems.get(fileName); |
| | | if (elems != null) |
| | | { |
| | | return elems; |
| | | } |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | private <T extends SchemaFileElement> LinkedHashMap<String, List<T>> copy( |
| | | LinkedHashSet<T> elemsToAdd) |
| | | { |
| | | LinkedHashMap<String, List<T>> hmElems = |
| | | new LinkedHashMap<String, List<T>>(); |
| | | for (T elem : elemsToAdd) |
| | | { |
| | | String fileName = CommonSchemaElements.getSchemaFile(elem); |
| | | if (fileName == null) |
| | | { |
| | | fileName = ""; |
| | | } |
| | | List<T> elems = hmElems.get(fileName); |
| | | if (elems == null) |
| | | { |
| | | elems = new ArrayList<T>(); |
| | | hmElems.put(fileName, elems); |
| | | } |
| | | elems.add(elem); |
| | | } |
| | | return hmElems; |
| | | } |
| | | |
| | | private void addAttributeOnline(final AttributeType attribute) |
| | | throws OpenDsException |
| | | { |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void run() |
| | | { |
| | | printEquivalentCommandLineToAddOnline(attribute); |
| | |
| | | notifyConfigurationElementCreated(attribute); |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | getProgressDialog().appendProgressHtml( |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void run() |
| | | { |
| | | printEquivalentCommandLineToAddOnline(objectClass); |
| | |
| | | notifyConfigurationElementCreated(objectClass); |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | getProgressDialog().appendProgressHtml( |
| | |
| | | |
| | | private String getValueOffline(CommonSchemaElements element) |
| | | { |
| | | Iterable<String> previousValues = |
| | | element.getExtraProperty(ServerConstants.SCHEMA_PROPERTY_FILENAME); |
| | | element.setExtraProperty(ServerConstants.SCHEMA_PROPERTY_FILENAME, |
| | | (String)null); |
| | | final Map<String, List<String>> props = element.getExtraProperties(); |
| | | List<String> previousValues = |
| | | props.get(ServerConstants.SCHEMA_PROPERTY_FILENAME); |
| | | setExtraProperty(element, ServerConstants.SCHEMA_PROPERTY_FILENAME, null); |
| | | String attributeWithoutFileDefinition = element.toString(); |
| | | |
| | | if (previousValues != null) |
| | | if (previousValues != null && !previousValues.isEmpty()) |
| | | { |
| | | ArrayList<String> vs = new ArrayList<String>(); |
| | | for (String s : previousValues) |
| | | { |
| | | vs.add(s); |
| | | } |
| | | if (!vs.isEmpty()) |
| | | { |
| | | element.setExtraProperty(ServerConstants.SCHEMA_PROPERTY_FILENAME, vs); |
| | | } |
| | | ArrayList<String> vs = new ArrayList<String>(previousValues); |
| | | element.setExtraProperty(ServerConstants.SCHEMA_PROPERTY_FILENAME, vs); |
| | | } |
| | | return attributeWithoutFileDefinition; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private String getFileName(CommonSchemaElements element) |
| | | { |
| | | String value = null; |
| | | Iterable<String> vs = |
| | | element.getExtraProperty(ServerConstants.SCHEMA_PROPERTY_FILENAME); |
| | | if (vs != null) |
| | | { |
| | | if (vs.iterator().hasNext()) |
| | | { |
| | | value = vs.iterator().next(); |
| | | } |
| | | } |
| | | return value; |
| | | } |
| | | |
| | | private void updateSchemaOffline(String file, |
| | | final List<AttributeType> attributes, |
| | | final List<ObjectClass> objectClasses) throws OpenDsException |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void run() |
| | | { |
| | | printEquivalentCommandToAddOffline(fileName, isSchemaFileDefined, |
| | |
| | | } |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | getProgressDialog().appendProgressHtml( |