/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2011-2015 ForgeRock AS. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
*/
/**
* This class determines how a service schema has changed between the current
* version and the new version in the war file.
*
* @author steve
*/
public class ServiceSchemaModifications {
private boolean isServiceModified = false;
private boolean hasSubSchemaChanges = false;
private boolean hasSchemaChanges = false;
public ServiceSchemaModifications(String serviceName, Document schemaDoc, SSOToken adminToken, boolean newService)
throws UpgradeException {
this.serviceName = serviceName;
this.serviceSchemaDoc = schemaDoc;
this.adminToken = adminToken;
if (newService) {
} else {
}
}
public boolean isServiceModified() {
return isServiceModified;
}
public boolean hasSchemaChanges() {
return hasSchemaChanges;
}
public boolean hasSubSchemaChanges() {
return hasSubSchemaChanges;
}
return schemaModifications;
}
return modifications;
}
return subSchemaChanges;
}
/**
* Get the wrapper that wraps the new service and any modifications it might have.
* @return The service wrapper.
*/
return newServiceWrapper;
}
//we should only fetch these once to prevent performance problems, also in case of fetchNew to prevent
//encrypting passwords multiple times.
" modifications were made to " + serviceName);
}
}
//we should only fetch these once to prevent performance problems, also in case of fetchNew to prevent
//encrypting passwords multiple times.
try {
} catch (SMSException smse) {
} catch (SSOException ssoe) {
}
}
hasSchemaChanges = true;
}
// sub schemas added or removed?
}
hasSubSchemaChanges = true;
}
// has the service changed
}
isServiceModified = true;
}
}
}
}
return schemas;
}
//NB: only schema additions are currently supported.
}
}
return !schemaModifications.isEmpty();
}
try {
if (subSchemaAdded.subSchemaChanged()) {
}
}
} catch (SMSException smse) {
UpgradeUtils.debug.error("error whilst determining sub schema changes for service: " + serviceName, smse);
}
UpgradeUtils.debug.message("calculateSubSchemaChanges returning " + (!(subSchemaChanges.isEmpty())));
}
return !(subSchemaChanges.isEmpty());
}
throws SMSException {
} else {
if (subSchemaAddedResult.subSchemaChanged()) {
}
}
}
}
return subSchemaAddedResult;
}
try {
//this is a new schema, that's not available in the existing schema, should be covered by
//calculateSchemaChanges
continue;
}
schema);
schema);
schema);
if (attrsAdded.hasBeenModified() || attrsModified.hasBeenModified() || attrsDeleted.hasBeenModified()) {
}
}
} catch (SMSException smse) {
UpgradeUtils.debug.error("error whilst determining schema changes for service: " + serviceName, smse);
}
UpgradeUtils.debug.message("calculateServiceModifications returning " + (!(modifications.isEmpty())));
}
return !(modifications.isEmpty());
}
throws SMSException, UpgradeException {
ServiceSchemaModificationWrapper attrAddedResult = new ServiceSchemaModificationWrapper(serviceName, schemaName);
attrsAdded = getAttributesAdded(newSchema.getAttributeSchemas(), existingSchema.getAttributeSchemas());
}
if (!(attrsAdded.isEmpty())) {
}
// new sub schema so skip attribute checking
continue;
}
if (subSchemaResult.hasBeenModified()) {
}
}
}
return attrAddedResult;
}
throws SMSException, UpgradeException {
ServiceSchemaModificationWrapper attrModifiedResult = new ServiceSchemaModificationWrapper(serviceName, schemaName);
attrsModified = getAttributesModified(newSchema.getAttributeSchemas(), existingSchema.getAttributeSchemas());
}
if (!(attrsModified.isEmpty())) {
}
// new sub schema so skip attribute checking
continue;
}
if (subSchemaResult.hasBeenModified()) {
}
}
}
return attrModifiedResult;
}
throws SMSException {
ServiceSchemaModificationWrapper attrDeletedResult = new ServiceSchemaModificationWrapper(serviceName, schemaName);;
attrsDeleted = getAttributesDeleted(newSchema.getAttributeSchemas(), existingSchema.getAttributeSchemas());
}
if (!(attrsDeleted.isEmpty())) {
}
// new sub schema so skip attribute checking
continue;
}
if (subSchemaResult.hasBeenModified()) {
}
}
}
return attrDeletedResult;
}
boolean found = false;
found = true;
}
}
if (!found) {
if (serviceHelper != null) {
}
}
}
return attrAdded;
}
private Set<AttributeSchemaImpl> getAttributesModified(Set<AttributeSchemaImpl> newAttrs, Set<AttributeSchemaImpl> existingAttrs)
throws UpgradeException {
// skip attributes that are not explicitly named for upgrade
continue;
}
continue;
}
try {
if (upgradedAttr != null) {
}
} catch (UpgradeException ue) {
throw ue;
}
}
}
return attrMods;
}
private Set<AttributeSchemaImpl> getAttributesDeleted(Set<AttributeSchemaImpl> newAttrs, Set<AttributeSchemaImpl> existingAttrs) {
boolean found = false;
found = true;
}
}
if (!found) {
}
}
return attrDeleted;
}
throws UpgradeException {
try {
} catch (SMSException smse) {
throw new UpgradeException(smse);
}
return schemas;
}
private Map<String, ServiceSchemaImpl> fetchExistingServiceAttributes(String serviceName, SSOToken adminToken)
throws SMSException, SSOException {
return schemas;
}
/**
* This will use the service schemas to find any upgrade handlers registered for the service and
* populate the NewServiceWrapper's ServiceSchemaModificationWrappers.
* @param newSchemaMap The service schemas representing the service.
* @throws UpgradeException If an upgrade error occurs.
*/
private void createServiceModifications(Map<String, ServiceSchemaImpl> newSchemaMap) throws UpgradeException {
try {
if (attributesAdded.hasBeenModified()) {
}
}
} catch (SMSException smse) {
UpgradeUtils.debug.error("Error whilst determining schema changes for service: " + serviceName, smse);
}
}
/**
* This will recursively go through the service schema and add modifications if any was found.
*
* @param schemaName Name of the schema being processed.
* @param newSchema The schema being processed.
* @return The schema modification wrapper.
* @throws UpgradeException If an error occurred during attribute upgrade.
*/
throws SMSException, UpgradeException {
final Set<AttributeSchemaImpl> attrsModified = getAttributesModified(newSchema.getAttributeSchemas());
if (!attrsModified.isEmpty()) {
}
}
if (subSchemaResult.hasBeenModified()) {
}
}
}
return attrModifiedResult;
}
/**
* This will find the service helper specified for a newly added service if one is registered.
* If any attributes are registered they will be passed to the helper for modification.
* @param newAttrs The new attributes being added by this service.
* @return The modified attributes.
* @throws UpgradeException If an error occurred during attribute upgrade.
*/
private Set<AttributeSchemaImpl> getAttributesModified(Set<AttributeSchemaImpl> newAttrs) throws UpgradeException {
// skip attributes that are not explicitly named for upgrade
continue;
}
try {
if (upgradedAttr != null) {
}
} catch (UpgradeException ue) {
throw ue;
}
}
}
return attrMods;
}
}