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() {
}
};
}
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;
}
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;
}
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;
}
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;
}
Aggregations