use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class BeanUnmarshaller method unmarshallToAnyValue.
private <T, S> void unmarshallToAnyValue(T bean, Class beanClass, S subBean, Class objectFactoryClass, Object objectFactory, Method elementFactoryMethod, Method getter, ParsingContext pc) {
JAXBElement<S> subBeanElement;
try {
subBeanElement = (JAXBElement<S>) elementFactoryMethod.invoke(objectFactory, subBean);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e1) {
throw new IllegalArgumentException("Cannot invoke factory method " + elementFactoryMethod + " on " + objectFactoryClass + " with " + subBean + ": " + e1, e1);
}
Collection<Object> col;
Object getterReturn;
try {
getterReturn = getter.invoke(bean);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new SystemException("Cannot invoke getter " + getter + " on bean of type " + beanClass + ": " + e.getMessage(), e);
}
try {
col = (Collection<Object>) getterReturn;
} catch (ClassCastException e) {
throw new SystemException("Getter " + getter + " on bean of type " + beanClass + " returned " + getterReturn + " instead of collection");
}
col.add(subBeanElement != null ? subBeanElement.getValue() : null);
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class WebComponentUtil method dispatchToObjectDetailsPage.
public static void dispatchToObjectDetailsPage(Class<? extends ObjectType> objectClass, String oid, Component component, boolean failIfUnsupported) {
PageParameters parameters = new PageParameters();
parameters.add(OnePageParameterEncoder.PARAMETER, oid);
Class<? extends PageBase> page = getObjectDetailsPage(objectClass);
if (page != null) {
((PageBase) component.getPage()).navigateToNext(page, parameters);
} else if (failIfUnsupported) {
throw new SystemException("Cannot determine details page for " + objectClass);
}
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class CertDefinitionDto method updateScopeDefinition.
public void updateScopeDefinition(PrismContext prismContext) {
AccessCertificationAssignmentReviewScopeType scopeTypeObj = null;
if (definitionScopeDto != null) {
scopeTypeObj = new AccessCertificationAssignmentReviewScopeType(prismContext);
scopeTypeObj.setName(definitionScopeDto.getName());
scopeTypeObj.setDescription(definitionScopeDto.getDescription());
scopeTypeObj.setObjectType(definitionScopeDto.getObjectType() != null ? new QName(definitionScopeDto.getObjectType().name()) : null);
SearchFilterType parsedSearchFilter = definitionScopeDto.getParsedSearchFilter(prismContext);
if (parsedSearchFilter != null) {
// check if everything is OK
try {
QueryConvertor.parseFilterPreliminarily(parsedSearchFilter.getFilterClauseXNode(), prismContext);
} catch (SchemaException e) {
throw new SystemException("Couldn't parse search filter: " + e.getMessage(), e);
}
}
scopeTypeObj.setSearchFilter(parsedSearchFilter);
scopeTypeObj.setIncludeAssignments(definitionScopeDto.isIncludeAssignments());
scopeTypeObj.setIncludeInducements(definitionScopeDto.isIncludeInducements());
scopeTypeObj.setIncludeResources(definitionScopeDto.isIncludeResources());
scopeTypeObj.setIncludeRoles(definitionScopeDto.isIncludeRoles());
scopeTypeObj.setIncludeOrgs(definitionScopeDto.isIncludeOrgs());
scopeTypeObj.setIncludeServices(definitionScopeDto.isIncludeServices());
scopeTypeObj.setIncludeUsers(definitionScopeDto.isIncludeUsers());
scopeTypeObj.setEnabledItemsOnly(definitionScopeDto.isEnabledItemsOnly());
scopeTypeObj.setItemSelectionExpression(definitionScopeDto.getItemSelectionExpression());
scopeTypeObj.getRelation().addAll(definitionScopeDto.getRelationList());
}
definition.setScopeDefinition(scopeTypeObj);
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class DefinitionScopeDto method getParsedSearchFilter.
public SearchFilterType getParsedSearchFilter(PrismContext context) {
if (searchFilterText == null || searchFilterText.isEmpty()) {
return null;
}
SearchFilterType rv = new SearchFilterType();
RootXNode filterClauseNode;
try {
filterClauseNode = (RootXNode) context.parserFor(searchFilterText).xml().parseToXNode();
} catch (SchemaException e) {
throw new SystemException("Cannot parse search filter " + searchFilterText + ": " + e.getMessage(), e);
}
rv.setFilterClauseXNode(filterClauseNode);
return rv;
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class ShadowIntegrityCheckResultHandler method checkShadow.
private void checkShadow(ShadowCheckResult checkResult, PrismObject<ShadowType> shadow, Task workerTask, OperationResult result) throws SchemaException {
ShadowType shadowType = shadow.asObjectable();
ObjectReferenceType resourceRef = shadowType.getResourceRef();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Checking shadow {} (resource {})", ObjectTypeUtil.toShortString(shadowType), resourceRef != null ? resourceRef.getOid() : "(null)");
}
statistics.incrementShadows();
if (resourceRef == null) {
checkResult.recordError(Statistics.NO_RESOURCE_OID, new SchemaException("No resourceRef"));
fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE_OID);
applyFixes(checkResult, shadow, workerTask, result);
return;
}
String resourceOid = resourceRef.getOid();
if (resourceOid == null) {
checkResult.recordError(Statistics.NO_RESOURCE_OID, new SchemaException("Null resource OID"));
fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE_OID);
applyFixes(checkResult, shadow, workerTask, result);
return;
}
PrismObject<ResourceType> resource = resources.get(resourceOid);
if (resource == null) {
statistics.incrementResources();
try {
resource = provisioningService.getObject(ResourceType.class, resourceOid, null, workerTask, result);
} catch (ObjectNotFoundException e) {
checkResult.recordError(Statistics.NO_RESOURCE, new ObjectNotFoundException("Resource object does not exist: " + e.getMessage(), e));
fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE);
applyFixes(checkResult, shadow, workerTask, result);
return;
} catch (SchemaException e) {
checkResult.recordError(Statistics.CANNOT_GET_RESOURCE, new SchemaException("Resource object has schema problems: " + e.getMessage(), e));
return;
} catch (CommonException | RuntimeException e) {
checkResult.recordError(Statistics.CANNOT_GET_RESOURCE, new SystemException("Resource object cannot be fetched for some reason: " + e.getMessage(), e));
return;
}
resources.put(resourceOid, resource);
}
checkResult.setResource(resource);
ShadowKindType kind = shadowType.getKind();
if (kind == null) {
// TODO or simply assume account?
checkResult.recordError(Statistics.NO_KIND_SPECIFIED, new SchemaException("No kind specified"));
return;
}
if (checkExtraData) {
checkOrFixShadowActivationConsistency(checkResult, shadow, fixExtraData);
}
PrismObject<ShadowType> fetchedShadow = null;
if (checkFetch) {
fetchedShadow = fetchShadow(checkResult, shadow, resource, workerTask, result);
if (fetchedShadow != null) {
shadow.setUserData(KEY_EXISTS_ON_RESOURCE, "true");
}
}
if (checkOwners) {
List<PrismObject<FocusType>> owners = searchOwners(shadow, result);
if (owners != null) {
shadow.setUserData(KEY_OWNERS, owners);
if (owners.size() > 1) {
checkResult.recordError(Statistics.MULTIPLE_OWNERS, new SchemaException("Multiple owners: " + owners));
}
}
if (shadowType.getSynchronizationSituation() == SynchronizationSituationType.LINKED && (owners == null || owners.isEmpty())) {
checkResult.recordError(Statistics.LINKED_WITH_NO_OWNER, new SchemaException("Linked shadow with no owner"));
}
if (shadowType.getSynchronizationSituation() != SynchronizationSituationType.LINKED && owners != null && !owners.isEmpty()) {
checkResult.recordError(Statistics.NOT_LINKED_WITH_OWNER, new SchemaException("Shadow with an owner but not marked as linked (marked as " + shadowType.getSynchronizationSituation() + ")"));
}
}
String intent = shadowType.getIntent();
if (checkIntents && (intent == null || intent.isEmpty())) {
checkResult.recordWarning(Statistics.NO_INTENT_SPECIFIED, "None or empty intent");
}
if (fixIntents && (intent == null || intent.isEmpty())) {
doFixIntent(checkResult, fetchedShadow, shadow, resource, workerTask, result);
}
Pair<String, ShadowKindType> key = new ImmutablePair<>(resourceOid, kind);
ObjectTypeContext context = contextMap.get(key);
if (context == null) {
context = new ObjectTypeContext();
context.setResource(resource);
RefinedResourceSchema resourceSchema;
try {
resourceSchema = RefinedResourceSchemaImpl.getRefinedSchema(context.getResource(), LayerType.MODEL, prismContext);
} catch (SchemaException e) {
checkResult.recordError(Statistics.CANNOT_GET_REFINED_SCHEMA, new SchemaException("Couldn't derive resource schema: " + e.getMessage(), e));
return;
}
if (resourceSchema == null) {
checkResult.recordError(Statistics.NO_RESOURCE_REFINED_SCHEMA, new SchemaException("No resource schema"));
return;
}
context.setObjectClassDefinition(resourceSchema.getRefinedDefinition(kind, shadowType));
if (context.getObjectClassDefinition() == null) {
// TODO or warning only?
checkResult.recordError(Statistics.NO_OBJECT_CLASS_REFINED_SCHEMA, new SchemaException("No refined object class definition for kind=" + kind + ", intent=" + intent));
return;
}
contextMap.put(key, context);
}
try {
provisioningService.applyDefinition(shadow, workerTask, result);
} catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
checkResult.recordError(Statistics.OTHER_FAILURE, new SystemException("Couldn't apply definition to shadow from repo", e));
return;
}
Set<RefinedAttributeDefinition<?>> identifiers = new HashSet<>();
Collection<? extends RefinedAttributeDefinition<?>> primaryIdentifiers = context.getObjectClassDefinition().getPrimaryIdentifiers();
identifiers.addAll(primaryIdentifiers);
identifiers.addAll(context.getObjectClassDefinition().getSecondaryIdentifiers());
PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer == null) {
// might happen on unfinished shadows?
checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("No attributes container"));
return;
}
for (RefinedAttributeDefinition<?> identifier : identifiers) {
PrismProperty property = attributesContainer.getValue().findProperty(identifier.getName());
if (property == null || property.size() == 0) {
checkResult.recordWarning(Statistics.OTHER_FAILURE, "No value for identifier " + identifier.getName());
continue;
}
if (property.size() > 1) {
// we don't expect multi-valued identifiers
checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("Multi-valued identifier " + identifier.getName() + " with values " + property.getValues()));
continue;
}
// size == 1
String value = (String) property.getValue().getValue();
if (value == null) {
checkResult.recordWarning(Statistics.OTHER_FAILURE, "Null value for identifier " + identifier.getName());
continue;
}
if (checkUniqueness) {
if (!checkDuplicatesOnPrimaryIdentifiersOnly || primaryIdentifiers.contains(identifier)) {
addIdentifierValue(checkResult, context, identifier.getName(), value, shadow);
}
}
if (checkNormalization) {
doCheckNormalization(checkResult, identifier, value, context);
}
}
applyFixes(checkResult, shadow, workerTask, result);
}
Aggregations