use of org.forgerock.openam.upgrade.ServiceSchemaUpgradeWrapper in project OpenAM by OpenRock.
the class UpgradeServiceSchemaStep method getDetailedReport.
@Override
public String getDetailedReport(String delimiter) {
Map<String, String> tags = new HashMap<String, String>();
tags.put(LF, delimiter);
if (!modifiedSchemas.isEmpty()) {
StringBuilder sBuf = new StringBuilder();
for (Map.Entry<String, Set<SchemaUpgradeWrapper>> schemaMod : modifiedSchemas.entrySet()) {
sBuf.append(BULLET).append(schemaMod.getKey()).append(delimiter);
for (SchemaUpgradeWrapper schemaUpgradeWrapper : schemaMod.getValue()) {
sBuf.append(INDENT).append(schemaUpgradeWrapper.getNewSchema().getSchemaName()).append(delimiter);
}
sBuf.append(delimiter);
}
tags.put(NEW_SCHEMAS, sBuf.toString());
} else {
tags.put(NEW_SCHEMAS, BUNDLE.getString("upgrade.none"));
}
if (addedServices != null && !addedServices.isEmpty()) {
StringBuilder aBuf = new StringBuilder();
for (NewServiceWrapper added : addedServices) {
aBuf.append(BULLET).append(added.getServiceName()).append(delimiter);
}
tags.put(NEW_SERVICES, aBuf.toString());
} else {
tags.put(NEW_SERVICES, BUNDLE.getString("upgrade.none"));
}
if (!modifiedServices.isEmpty()) {
StringBuilder mBuf = new StringBuilder();
for (Map.Entry<String, Map<String, ServiceSchemaUpgradeWrapper>> mod : modifiedServices.entrySet()) {
mBuf.append(BULLET).append(mod.getKey()).append(delimiter);
for (Map.Entry<String, ServiceSchemaUpgradeWrapper> serviceType : mod.getValue().entrySet()) {
ServiceSchemaUpgradeWrapper sUpdate = serviceType.getValue();
if (sUpdate != null) {
if (sUpdate.getAttributesAdded() != null && sUpdate.getAttributesAdded().hasBeenModified()) {
mBuf.append(calculateAttrModifications(BUNDLE.getString("upgrade.addattr"), sUpdate.getAttributesAdded(), delimiter));
}
if (sUpdate.getAttributesModified() != null && sUpdate.getAttributesModified().hasBeenModified()) {
mBuf.append(calculateAttrModifications(BUNDLE.getString("upgrade.modattr"), sUpdate.getAttributesModified(), delimiter));
}
if (sUpdate.getAttributesDeleted() != null && sUpdate.getAttributesDeleted().hasBeenModified()) {
mBuf.append(calculateAttrModifications(BUNDLE.getString("upgrade.delattr"), sUpdate.getAttributesDeleted(), delimiter));
}
}
}
}
tags.put(MODIFIED_SERVICES, mBuf.toString());
} else {
tags.put(MODIFIED_SERVICES, BUNDLE.getString("upgrade.none"));
}
if (!modifiedSubSchemas.isEmpty()) {
StringBuilder ssBuf = new StringBuilder();
for (Map.Entry<String, Map<String, SubSchemaUpgradeWrapper>> ssMod : modifiedSubSchemas.entrySet()) {
ssBuf.append(BULLET).append(ssMod.getKey()).append(delimiter);
for (Map.Entry<String, SubSchemaUpgradeWrapper> serviceType : ssMod.getValue().entrySet()) {
SubSchemaUpgradeWrapper ssUpdate = serviceType.getValue();
if (ssUpdate != null) {
if (ssUpdate.getSubSchemasAdded() != null && ssUpdate.getSubSchemasAdded().subSchemaChanged()) {
ssBuf.append(INDENT).append(calculateSubSchemaAdditions(ssUpdate.getSubSchemasAdded(), delimiter));
}
}
ssBuf.append(delimiter);
}
}
tags.put(NEW_SUB_SCHEMAS, ssBuf.toString());
} else {
tags.put(NEW_SUB_SCHEMAS, BUNDLE.getString("upgrade.none"));
}
if (!deletedServices.isEmpty()) {
StringBuilder dBuf = new StringBuilder();
for (String serviceName : deletedServices) {
dBuf.append(BULLET).append(serviceName).append(delimiter);
}
tags.put(DELETED_SERVICES, dBuf.toString());
} else {
tags.put(DELETED_SERVICES, BUNDLE.getString("upgrade.none"));
}
return tagSwapReport(tags, "upgrade.servicereport");
}
use of org.forgerock.openam.upgrade.ServiceSchemaUpgradeWrapper in project OpenAM by OpenRock.
the class ServiceSchemaModifications method calculateServiceModifications.
private boolean calculateServiceModifications(Map<String, ServiceSchemaImpl> newSchemaMap, Map<String, ServiceSchemaImpl> existingSchemaMap) throws UpgradeException {
modifications = new HashMap<String, ServiceSchemaUpgradeWrapper>();
try {
for (Map.Entry<String, ServiceSchemaImpl> newAttrSchemaEntry : newSchemaMap.entrySet()) {
ServiceSchemaImpl schema = existingSchemaMap.get(newAttrSchemaEntry.getKey());
if (schema == null) {
//calculateSchemaChanges
continue;
}
ServiceSchemaModificationWrapper attrsAdded = getServiceAdditionsRecursive(newAttrSchemaEntry.getKey(), newAttrSchemaEntry.getValue(), schema);
ServiceSchemaModificationWrapper attrsModified = getServiceModificationsRecursive(newAttrSchemaEntry.getKey(), newAttrSchemaEntry.getValue(), schema);
ServiceSchemaModificationWrapper attrsDeleted = getServiceDeletionsRecursive(newAttrSchemaEntry.getKey(), newAttrSchemaEntry.getValue(), schema);
if (attrsAdded.hasBeenModified() || attrsModified.hasBeenModified() || attrsDeleted.hasBeenModified()) {
modifications.put(newAttrSchemaEntry.getKey(), new ServiceSchemaUpgradeWrapper(attrsAdded, attrsModified, attrsDeleted));
}
}
} catch (SMSException smse) {
UpgradeUtils.debug.error("error whilst determining schema changes for service: " + serviceName, smse);
throw new UpgradeException(smse.getMessage());
}
if (UpgradeUtils.debug.messageEnabled()) {
UpgradeUtils.debug.message("calculateServiceModifications returning " + (!(modifications.isEmpty())));
}
return !(modifications.isEmpty());
}
use of org.forgerock.openam.upgrade.ServiceSchemaUpgradeWrapper in project OpenAM by OpenRock.
the class UpgradeServiceSchemaStep method perform.
@Override
public void perform() throws UpgradeException {
UpgradeProgress.reportStart("upgrade.upgradeservices");
UpgradeProgress.reportEnd("upgrade.blank");
if (!addedServices.isEmpty()) {
StringBuilder buffer = new StringBuilder();
if (DEBUG.messageEnabled()) {
buffer.append("services to add: ");
}
for (NewServiceWrapper serviceToAdd : addedServices) {
final StringBuilder serviceDefinition = new StringBuilder(SERVICE_PROLOG);
serviceDefinition.append(XMLUtils.print(serviceToAdd.getServiceDocument()));
UpgradeProgress.reportStart("upgrade.addservice", serviceToAdd.getServiceName());
UpgradeUtils.createService(serviceDefinition.toString(), serviceToAdd, getAdminToken());
UpgradeProgress.reportEnd("upgrade.success");
if (DEBUG.messageEnabled()) {
buffer.append(serviceToAdd.getServiceName()).append(": ");
}
}
if (DEBUG.messageEnabled()) {
DEBUG.message("services to add: " + buffer.toString());
}
}
if (!modifiedSchemas.isEmpty()) {
for (Map.Entry<String, Set<SchemaUpgradeWrapper>> entry : modifiedSchemas.entrySet()) {
String serviceName = entry.getKey();
for (SchemaUpgradeWrapper schemaUpgradeWrapper : entry.getValue()) {
UpgradeProgress.reportStart("upgrade.addschema", schemaUpgradeWrapper.getNewSchema().getSchemaName(), serviceName);
UpgradeUtils.addNewSchema(serviceName, schemaUpgradeWrapper, getAdminToken());
UpgradeProgress.reportEnd("upgrade.success");
}
if (DEBUG.messageEnabled()) {
DEBUG.message("modified schema: " + serviceName);
}
}
}
if (!modifiedServices.isEmpty()) {
for (Map.Entry<String, Map<String, ServiceSchemaUpgradeWrapper>> serviceToModify : modifiedServices.entrySet()) {
UpgradeProgress.reportStart("upgrade.modservice", serviceToModify.getKey());
UpgradeUtils.modifyService(serviceToModify.getKey(), serviceToModify.getValue(), getAdminToken());
UpgradeProgress.reportEnd("upgrade.success");
if (DEBUG.messageEnabled()) {
DEBUG.message("modified service: " + serviceToModify.getKey());
}
}
}
if (!modifiedSubSchemas.isEmpty()) {
for (Map.Entry<String, Map<String, SubSchemaUpgradeWrapper>> ssMod : modifiedSubSchemas.entrySet()) {
UpgradeProgress.reportStart("upgrade.addsubschema", ssMod.getKey());
UpgradeUtils.addNewSubSchemas(ssMod.getKey(), ssMod.getValue(), getAdminToken());
UpgradeProgress.reportEnd("upgrade.success");
if (DEBUG.messageEnabled()) {
DEBUG.message("modified sub schema: " + ssMod.getKey());
}
}
}
if (!deletedServices.isEmpty()) {
for (String serviceToDelete : deletedServices) {
UpgradeProgress.reportStart("upgrade.delservice", serviceToDelete);
UpgradeUtils.deleteService(serviceToDelete, getAdminToken());
UpgradeProgress.reportEnd("upgrade.success");
if (DEBUG.messageEnabled()) {
DEBUG.message("deleted service: " + serviceToDelete);
}
}
}
}
Aggregations