NewSchemaElementsTask.java revision 2d3af58c2cee0a4a12390fae1eace3fdd15d9664
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2009 Sun Microsystems, Inc.
* Portions Copyright 2013-2015 ForgeRock AS.
*/
/**
* An abstract class used to re-factor some code between the different tasks
* that create elements in the schema.
*/
public class NewSchemaElementsTask extends Task
{
/**
* Constructor of the task.
*
* @param info
* the control panel information.
* @param dlg
* the progress dialog where the task progress will be displayed.
* @param ocsToAdd
* the object classes that must be created in order.
* @param attrsToAdd
* the attributes that must be created in order.
*/
public NewSchemaElementsTask(
ControlPanelInfo info, ProgressDialog dlg, Set<ObjectClass> ocsToAdd, Set<AttributeType> attrsToAdd)
{
}
{
return Collections.emptySet();
}
public boolean canLaunch(Task taskToBeLaunched, Collection<LocalizableMessage> incompatibilityReasons)
{
{
return false;
}
return true;
}
public void runTask()
{
try
{
updateSchema();
}
catch (Throwable t)
{
lastException = t;
}
}
{
return Type.NEW_SCHEMA_ELEMENT;
}
public LocalizableMessage getTaskDescription()
{
{
return INFO_CTRL_PANEL_NEW_ATTRIBUTE_TASK_DESCRIPTION.get(attrsToAdd.iterator().next().getNameOrOID());
}
{
return INFO_CTRL_PANEL_NEW_OBJECTCLASS_TASK_DESCRIPTION.get(ocsToAdd.iterator().next().getNameOrOID());
}
else
{
{
}
{
}
else
{
}
}
}
private <T extends CommonSchemaElements> List<String> getElementsNameOrOID(final Set<T> schemaElements)
{
{
}
return nameOrOIDs;
}
/**
* Update the schema.
*
* @throws OpenDsException
* if an error occurs.
*/
private void updateSchema() throws OpenDsException
{
if (isServerRunning())
{
}
else
{
}
}
protected String getCommandLinePath()
{
return null;
}
{
return Collections.emptyList();
}
/**
* Add the schema elements one by one: we are not sure that the server will
* handle the adds sequentially if we only send one modification.
*
* @throws OpenDsException
*/
private void updateSchemaOnline() throws OpenDsException
{
{
}
{
}
}
private void appendNewLinesToProgress()
{
{
public void run()
{
getProgressDialog().appendProgressHtml(Utilities.applyFont("<br><br>", ColorAndFontConstants.progressFont));
}
});
}
private void updateSchemaOffline() throws OpenDsException
{
// Group the changes in the same schema file.
{
{
}
}
}
{
{
return elems;
}
return Collections.emptyList();
}
{
for (T elem : elemsToAdd)
{
{
fileName = "";
}
{
}
}
return hmElems;
}
{
addSchemaElementOnline(attribute, INFO_CTRL_PANEL_CREATING_ATTRIBUTE_PROGRESS.get(attribute.getNameOrOID()));
}
{
addSchemaElementOnline(objectClass, INFO_CTRL_PANEL_CREATING_OBJECTCLASS_PROGRESS.get(objectClass.getNameOrOID()));
}
private void addSchemaElementOnline(final CommonSchemaElements schemaElement, final LocalizableMessage progressMsg)
throws OpenDsException
{
{
public void run()
{
}
});
try
{
}
catch (NamingException ne)
{
}
{
public void run()
{
getProgressDialog().appendProgressHtml(Utilities.getProgressDone(ColorAndFontConstants.progressFont));
}
});
}
{
}
{
{
element.setExtraProperty(ServerConstants.SCHEMA_PROPERTY_FILENAME, new ArrayList<String>(previousValues));
}
return attributeWithoutFileDefinition;
}
{
.append("dn: cn=schema<br>")
.append("changetype: modify<br>")
getProgressDialog().appendProgressHtml(Utilities.applyFont(sb.toString(), ColorAndFontConstants.progressFont));
}
{
return element instanceof AttributeType ? ConfigConstants.ATTR_ATTRIBUTE_TYPES : ConfigConstants.ATTR_OBJECTCLASSES;
}
private void updateSchemaOffline(
String file, final List<AttributeType> attributes, final List<ObjectClass> objectClasses) throws OpenDsException
{
{
}
if (!f.isAbsolute())
{
}
{
public void run()
{
final String command = equivalentCommandToAddOffline(fileName, isSchemaFileDefined, schemaElements);
progressDialog.appendProgressHtml(Utilities.applyFont(command, ColorAndFontConstants.progressFont));
{
INFO_CTRL_PANEL_CREATING_ATTRIBUTE_PROGRESS.get(attributeName), ColorAndFontConstants.progressFont));
}
{
}
else
{
}
}
});
if (isSchemaFileDefined)
{
}
else
{
}
{
}
{
public void run()
{
getProgressDialog().appendProgressHtml(Utilities.getProgressDone(ColorAndFontConstants.progressFont));
}
});
}
private String equivalentCommandToAddOffline(
{
{
}
if (isSchemaFileDefined)
{
sb.append(INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_ADD_SCHEMA_ELEMENT_OFFLINE.get(namesString, schemaFile))
.append("<br><b>");
}
else
{
.append("<br><b>");
{
}
}
{
sb.append(getAttributeName(schemaElement)).append(": ").append(getValueOffline(schemaElement)).append("<br>");
}
}
/**
* Returns whether the file defined in the schema element exists or not.
*
* @param schemaFile
* the path to the schema file.
* @return <CODE>true</CODE> if the schema file is defined and
* <CODE>false</CODE> otherwise.
*/
{
{
}
catch (Throwable t)
{
return false;
}
}
/**
* Returns the list of LDIF lines that are enough to create the entry
* containing only the schema element associated with this task.
*
* @return the list of LDIF lines that are enough to create the entry
* containing only the schema element associated with this task.
*/
{
return lines;
}
/**
* Updates the contents of the schema file.
*
* @param schemaFile
* the schema file.
* @param isSchemaFileDefined
* whether the schema is defined or not.
* @param attributes
* the attributes to add.
* @param objectClasses
* the object classes to add.
* @throws OpenDsException
* if an error occurs updating the schema file.
*/
throws OpenDsException
{
try (final LDIFExportConfig exportConfig = new LDIFExportConfig(schemaFile, ExistingFileBehavior.OVERWRITE))
{
{
{
}
}
catch (Throwable t)
{
}
}
}
throws DirectoryException
{
{
}
}
private void updateSchemaUndefinedFile(String schemaFile, List<CommonSchemaElements> schemaElements)
throws OfflineUpdateException
{
{
{
}
{
}
}
catch (Throwable t)
{
}
}
}