Search in sources :

Example 66 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class PageReport method createFullXmlModel.

private IModel<String> createFullXmlModel() {
    return new IModel<String>() {

        @Override
        public String getObject() {
            PrismObject report = model.getObject().getObject();
            if (report == null) {
                return null;
            }
            try {
                return getPrismContext().serializeObjectToString(report, PrismContext.LANG_XML);
            } catch (SchemaException ex) {
                getSession().error(getString("PageReport.message.cantSerializeFromObjectToString") + ex);
                throw new RestartResponseException(PageError.class);
            }
        }

        @Override
        public void setObject(String object) {
            OperationResult result = new OperationResult(OPERATION_VALIDATE_REPORT);
            Holder<PrismObject<ReportType>> reportHolder = new Holder<>(null);
            try {
                validateObject(object, reportHolder, PrismContext.LANG_XML, true, result);
                model.getObject().setObject(reportHolder.getValue());
            } catch (Exception e) {
                LOGGER.error("Could not set object. Validation problem occured." + result.getMessage());
                result.recordFatalError("Could not set object. Validation problem occured,", e);
                showResult(result, "Could not set object. Validation problem occured.");
            }
        }

        @Override
        public void detach() {
        }
    };
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IModel(org.apache.wicket.model.IModel) RestartResponseException(org.apache.wicket.RestartResponseException) Holder(com.evolveum.midpoint.util.Holder) PageError(com.evolveum.midpoint.web.page.error.PageError) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 67 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class SynchronizationUtils method isPolicyApplicable.

public static boolean isPolicyApplicable(QName objectClass, ShadowKindType kind, String intent, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
    List<QName> policyObjectClasses = synchronizationPolicy.getObjectClass();
    if (policyObjectClasses == null || policyObjectClasses.isEmpty()) {
        String policyIntent = synchronizationPolicy.getIntent();
        ShadowKindType policyKind = synchronizationPolicy.getKind();
        ObjectClassComplexTypeDefinition policyObjectClass = null;
        RefinedResourceSchema schema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
        if (schema == null) {
            throw new SchemaException("No schema defined in resource. Possible configuration problem?");
        }
        if (policyKind == null && policyIntent == null) {
            policyObjectClass = schema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
        }
        if (policyKind != null) {
            if (StringUtils.isEmpty(policyIntent)) {
                policyObjectClass = schema.findDefaultObjectClassDefinition(policyKind);
            } else {
                policyObjectClass = schema.findObjectClassDefinition(policyKind, policyIntent);
            }
        }
        if (policyObjectClass != null && !policyObjectClass.getTypeName().equals(objectClass)) {
            return false;
        }
    }
    if (policyObjectClasses != null && !policyObjectClasses.isEmpty()) {
        if (!QNameUtil.contains(policyObjectClasses, objectClass)) {
            return false;
        }
    }
    // kind
    ShadowKindType policyKind = synchronizationPolicy.getKind();
    if (policyKind != null && kind != null && !policyKind.equals(kind)) {
        return false;
    }
    // intent
    // TODO is the intent always present in shadow at this time? [med]
    String policyIntent = synchronizationPolicy.getIntent();
    if (policyIntent != null && intent != null && !MiscSchemaUtil.equalsIntent(intent, policyIntent)) {
        return false;
    }
    return true;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema)

Example 68 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class RefinedObjectClassDefinitionImpl method parseRefinedObjectClass.

private static RefinedObjectClassDefinition parseRefinedObjectClass(ResourceObjectTypeDefinitionType schemaHandlingObjDefType, ResourceType resourceType, RefinedResourceSchema rSchema, PrismContext prismContext, @NotNull ShadowKindType kind, @NotNull String intent, String typeDesc, String contextDescription) throws SchemaException {
    ObjectClassComplexTypeDefinition objectClassDef;
    if (schemaHandlingObjDefType.getObjectClass() != null) {
        QName objectClass = schemaHandlingObjDefType.getObjectClass();
        objectClassDef = rSchema.getOriginalResourceSchema().findObjectClassDefinition(objectClass);
        if (objectClassDef == null) {
            throw new SchemaException("Object class " + objectClass + " as specified in " + typeDesc + " type " + schemaHandlingObjDefType.getIntent() + " was not found in the resource schema of " + contextDescription);
        }
    } else {
        throw new SchemaException("Definition of " + typeDesc + " type " + schemaHandlingObjDefType.getIntent() + " does not have objectclass, in " + contextDescription);
    }
    RefinedObjectClassDefinitionImpl rOcDef = new RefinedObjectClassDefinitionImpl(resourceType, objectClassDef);
    rOcDef.setKind(kind);
    rOcDef.schemaHandlingObjectTypeDefinitionType = schemaHandlingObjDefType;
    rOcDef.setIntent(intent);
    if (schemaHandlingObjDefType.getDisplayName() != null) {
        rOcDef.setDisplayName(schemaHandlingObjDefType.getDisplayName());
    } else {
        if (objectClassDef.getDisplayName() != null) {
            rOcDef.setDisplayName(objectClassDef.getDisplayName());
        }
    }
    if (schemaHandlingObjDefType.getDescription() != null) {
        rOcDef.setDescription(schemaHandlingObjDefType.getDescription());
    }
    if (schemaHandlingObjDefType.isDefault() != null) {
        rOcDef.setDefault(schemaHandlingObjDefType.isDefault());
    } else {
        rOcDef.setDefault(objectClassDef.isDefaultInAKind());
    }
    if (schemaHandlingObjDefType.getBaseContext() != null) {
        rOcDef.setBaseContext(schemaHandlingObjDefType.getBaseContext());
    }
    return rOcDef;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName)

Example 69 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class RefinedObjectClassDefinitionImpl method createBlankShadow.

@Override
public PrismObject<ShadowType> createBlankShadow(RefinedObjectClassDefinition definition) {
    PrismObject<ShadowType> accountShadow;
    try {
        accountShadow = getPrismContext().createObject(ShadowType.class);
    } catch (SchemaException e) {
        // This should not happen
        throw new SystemException("Internal error instantiating account shadow: " + e.getMessage(), e);
    }
    ShadowType accountShadowType = accountShadow.asObjectable();
    accountShadowType.setIntent(getIntent());
    accountShadowType.setKind(getKind());
    accountShadowType.setObjectClass(getObjectClassDefinition().getTypeName());
    accountShadowType.setResourceRef(ObjectTypeUtil.createObjectRef(getResourceType()));
    // Setup definition
    PrismObjectDefinition<ShadowType> newDefinition = accountShadow.getDefinition().cloneWithReplacedDefinition(ShadowType.F_ATTRIBUTES, definition.toResourceAttributeContainerDefinition());
    accountShadow.setDefinition(newDefinition);
    return accountShadow;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 70 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class RefinedObjectClassDefinitionImpl method convertToPattern.

private static ResourceObjectPattern convertToPattern(ResourceObjectPatternType patternType, RefinedObjectClassDefinition rAccountDef) throws SchemaException {
    ResourceObjectPattern resourceObjectPattern = new ResourceObjectPattern(rAccountDef);
    SearchFilterType filterType = patternType.getFilter();
    if (filterType != null) {
        ObjectFilter filter = QueryConvertor.parseFilter(filterType, rAccountDef.getObjectDefinition());
        resourceObjectPattern.addFilter(filter);
        return resourceObjectPattern;
    }
    // Deprecated
    if (patternType.getName() != null) {
        RefinedAttributeDefinition attributeDefinition = rAccountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA, "name"));
        if (attributeDefinition == null) {
            throw new SchemaException("No ICF NAME attribute in schema as specified in the definition of protected objects (this is deprecated syntax anyway, convert it to filter)");
        }
        ResourceAttribute<String> attr = attributeDefinition.instantiate();
        attr.setRealValue(patternType.getName());
        resourceObjectPattern.addIdentifier(attr);
    } else if (patternType.getUid() != null) {
        RefinedAttributeDefinition attributeDefinition = rAccountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA, "uid"));
        if (attributeDefinition == null) {
            throw new SchemaException("No ICF UID attribute in schema as specified in the definition of protected objects (this is deprecated syntax anyway, convert it to filter)");
        }
        ResourceAttribute<String> attr = attributeDefinition.instantiate();
        attr.setRealValue(patternType.getUid());
        resourceObjectPattern.addIdentifier(attr);
    } else {
        throw new SchemaException("No filter and no deprecated name/uid in resource object pattern");
    }
    return resourceObjectPattern;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceObjectPattern(com.evolveum.midpoint.common.ResourceObjectPattern) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Aggregations

SchemaException (com.evolveum.midpoint.util.exception.SchemaException)576 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)235 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)214 QName (javax.xml.namespace.QName)132 SystemException (com.evolveum.midpoint.util.exception.SystemException)113 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)100 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)100 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)92 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)89 Task (com.evolveum.midpoint.task.api.Task)87 PrismObject (com.evolveum.midpoint.prism.PrismObject)86 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)69 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)68 ArrayList (java.util.ArrayList)67 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)59 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)49 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)47 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)46 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)34 Test (org.testng.annotations.Test)34