private void log(String message, Object... params) { if (LOGGER.isTraceEnabled()) { LOGGER.trace(message, params); } if (PERFORMANCE_ADVISOR.isTraceEnabled()) { PERFORMANCE_ADVISOR.trace(message, params); } }
@PostConstruct private void initialize() { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Registering with taskManager as a handler for " + MODEL_OPERATION_TASK_URI); } taskManager.registerHandler(MODEL_OPERATION_TASK_URI, this); }
/** * Check whether system configuration has not changed in repository (e.g. by another node in * cluster). Applies new configuration if so. * * @param parentResult */ public void checkSystemConfigurationChanged(OperationResult parentResult) { OperationResult result = parentResult.createSubresult(CHECK_SYSTEM_CONFIGURATION_CHANGED); PrismObject<SystemConfigurationType> systemConfiguration; try { PrismObject<SystemConfigurationType> config = getRepositoryService() .getObject( SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, result); String versionInRepo = config.getVersion(); String versionApplied = LoggingConfigurationManager.getCurrentlyUsedVersion(); // we do not try to determine which one is "newer" - we simply use the one from repo if (!versionInRepo.equals(versionApplied)) { LoggingConfigurationType loggingConfig = ProfilingConfigurationManager.checkSystemProfilingConfiguration(config); LoggingConfigurationManager.configure(loggingConfig, versionInRepo, result); } else { if (LOGGER.isTraceEnabled()) { LOGGER.trace( "System configuration change check: version in repo = version currently applied = {}", versionApplied); } } if (result.isUnknown()) { result.computeStatus(); } } catch (ObjectNotFoundException e) { LoggingConfigurationManager .resetCurrentlyUsedVersion(); // because the new config (if any) will have version number // probably starting at 1 - so to be sure to read it when it // comes [hope this never occurs :)] String message = "No system configuration found, skipping application of system settings"; LOGGER.error(message + ": " + e.getMessage(), e); result.recordWarning(message, e); } catch (SchemaException e) { String message = "Schema error in system configuration, skipping application of system settings"; LOGGER.error(message + ": " + e.getMessage(), e); result.recordWarning(message, e); } catch (RuntimeException e) { String message = "Runtime exception in system configuration processing, skipping application of system settings"; LOGGER.error(message + ": " + e.getMessage(), e); result.recordWarning(message, e); } }
@Override public void notify(DelegateTask delegateTask) { if (LOGGER.isTraceEnabled()) { LOGGER.trace( "notify called; event name = {}, name = {}", delegateTask.getEventName(), delegateTask.getName()); } ActivitiInterface activitiInterface = SpringApplicationContextHolder.getActivitiInterface(); activitiInterface.notifyMidpointAboutTaskEvent(delegateTask); }
private void traceFailure( ExpressionEvaluationContext context, ExpressionVariables processedVariables, Exception e) { LOGGER.error( "Error evaluating expression in {}: {}", new Object[] {context.getContextDescription(), e.getMessage(), e}); if (!LOGGER.isTraceEnabled()) { return; } StringBuilder sb = new StringBuilder(); sb.append("Expression failure:\n"); appendTraceHeader(sb, context, processedVariables); sb.append("\nERROR: ").append(e.getClass().getSimpleName()).append(": ").append(e.getMessage()); appendTraceFooter(sb); LOGGER.trace(sb.toString()); }
public RootHibernateQuery interpret( ObjectQuery query, Class<? extends Containerable> type, Collection<SelectorOptions<GetOperationOptions>> options, PrismContext prismContext, boolean countingObjects, Session session) throws QueryException { Validate.notNull(type, "Type must not be null."); Validate.notNull(session, "Session must not be null."); Validate.notNull(prismContext, "Prism context must not be null."); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Interpreting query for type '{}', query:\n{}", new Object[] {type, query}); } InterpretationContext context = new InterpretationContext(this, type, prismContext, session); interpretQueryFilter(context, query); interpretPagingAndSorting(context, query, countingObjects); RootHibernateQuery hibernateQuery = context.getHibernateQuery(); if (countingObjects) { hibernateQuery.addProjectionElement(new ProjectionElement("count(*)")); } else { String rootAlias = hibernateQuery.getPrimaryEntityAlias(); hibernateQuery.addProjectionElement(new ProjectionElement(rootAlias + ".fullObject")); // TODO other objects if parent is requested? if (context.isObject()) { hibernateQuery.addProjectionElement(new ProjectionElement(rootAlias + ".stringsCount")); hibernateQuery.addProjectionElement(new ProjectionElement(rootAlias + ".longsCount")); hibernateQuery.addProjectionElement(new ProjectionElement(rootAlias + ".datesCount")); hibernateQuery.addProjectionElement(new ProjectionElement(rootAlias + ".referencesCount")); hibernateQuery.addProjectionElement(new ProjectionElement(rootAlias + ".polysCount")); hibernateQuery.addProjectionElement(new ProjectionElement(rootAlias + ".booleansCount")); hibernateQuery.setResultTransformer(GetObjectResult.RESULT_TRANSFORMER); } else { hibernateQuery.addProjectionElement(new ProjectionElement(rootAlias + ".ownerOid")); hibernateQuery.setResultTransformer(GetContainerableResult.RESULT_TRANSFORMER); } } return hibernateQuery; }
private void traceSuccess( ExpressionEvaluationContext context, ExpressionVariables processedVariables, PrismValueDeltaSetTriple<V> outputTriple) { if (!LOGGER.isTraceEnabled()) { return; } StringBuilder sb = new StringBuilder(); sb.append("Expression trace:\n"); appendTraceHeader(sb, context, processedVariables); sb.append("\nResult: "); if (outputTriple == null) { sb.append("null"); } else { sb.append(outputTriple.toHumanReadableString()); } appendTraceFooter(sb); LOGGER.trace(sb.toString()); }
private void repositorySelfTestUser(Task task, OperationResult testResult) { OperationResult result = testResult.createSubresult(REPOSITORY_SELF_TEST_USER); PrismObject<UserType> user = getObjectDefinition(UserType.class).instantiate(); UserType userType = user.asObjectable(); String name = generateRandomName(); PolyStringType namePolyStringType = toPolyStringType(name); userType.setName(namePolyStringType); result.addContext("name", name); userType.setDescription(SelfTestData.POLICIJA); userType.setFullName(toPolyStringType(USER_FULL_NAME)); userType.setGivenName(toPolyStringType(USER_GIVEN_NAME)); userType.setFamilyName(toPolyStringType(USER_FAMILY_NAME)); userType.setTitle(toPolyStringType(INSANE_NATIONAL_STRING)); userType.getEmployeeType().add(USER_EMPLOYEE_TYPE[0]); userType.getEmployeeType().add(USER_EMPLOYEE_TYPE[1]); userType.getOrganization().add(toPolyStringType(USER_ORGANIZATION[0])); userType.getOrganization().add(toPolyStringType(USER_ORGANIZATION[1])); String oid; try { oid = repositoryService.addObject(user, null, result); } catch (ObjectAlreadyExistsException e) { result.recordFatalError(e); return; } catch (SchemaException e) { result.recordFatalError(e); return; } catch (RuntimeException e) { result.recordFatalError(e); return; } try { { OperationResult subresult = result.createSubresult(result.getOperation() + ".getObject"); PrismObject<UserType> userRetrieved; try { userRetrieved = repositoryService.getObject(UserType.class, oid, null, subresult); } catch (ObjectNotFoundException e) { result.recordFatalError(e); return; } catch (SchemaException e) { result.recordFatalError(e); return; } catch (RuntimeException e) { result.recordFatalError(e); return; } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Self-test:user getObject:\n{}", userRetrieved.debugDump()); } checkUser(userRetrieved, name, subresult); subresult.recordSuccessIfUnknown(); } { OperationResult subresult = result.createSubresult(result.getOperation() + ".searchObjects.fullName"); try { ObjectQuery query = new ObjectQuery(); ObjectFilter filter = EqualFilter.createEqual( UserType.F_FULL_NAME, UserType.class, prismContext, null, toPolyString(USER_FULL_NAME)); query.setFilter(filter); subresult.addParam("query", query); List<PrismObject<UserType>> foundObjects = repositoryService.searchObjects(UserType.class, query, null, subresult); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Self-test:user searchObjects:\n{}", DebugUtil.debugDump(foundObjects)); } assertSingleSearchResult("user", foundObjects, subresult); PrismObject<UserType> userRetrieved = foundObjects.iterator().next(); checkUser(userRetrieved, name, subresult); subresult.recordSuccessIfUnknown(); } catch (SchemaException e) { subresult.recordFatalError(e); return; } catch (RuntimeException e) { subresult.recordFatalError(e); return; } } // MID-1116 { OperationResult subresult = result.createSubresult(result.getOperation() + ".searchObjects.employeeType"); try { ObjectQuery query = new ObjectQuery(); ObjectFilter filter = EqualFilter.createEqual( UserType.F_EMPLOYEE_TYPE, UserType.class, prismContext, null, USER_EMPLOYEE_TYPE[0]); query.setFilter(filter); subresult.addParam("query", query); List<PrismObject<UserType>> foundObjects = repositoryService.searchObjects(UserType.class, query, null, subresult); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Self-test:user searchObjects:\n{}", DebugUtil.debugDump(foundObjects)); } assertSingleSearchResult("user", foundObjects, subresult); PrismObject<UserType> userRetrieved = foundObjects.iterator().next(); checkUser(userRetrieved, name, subresult); subresult.recordSuccessIfUnknown(); } catch (SchemaException e) { subresult.recordFatalError(e); return; } catch (RuntimeException e) { subresult.recordFatalError(e); return; } } // MID-1116 { OperationResult subresult = result.createSubresult(result.getOperation() + ".searchObjects.organization"); try { ObjectQuery query = new ObjectQuery(); ObjectFilter filter = EqualFilter.createEqual( UserType.F_ORGANIZATION, UserType.class, prismContext, null, toPolyString(USER_ORGANIZATION[1])); query.setFilter(filter); subresult.addParam("query", query); List<PrismObject<UserType>> foundObjects = repositoryService.searchObjects(UserType.class, query, null, subresult); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Self-test:user searchObjects:\n{}", DebugUtil.debugDump(foundObjects)); } assertSingleSearchResult("user", foundObjects, subresult); PrismObject<UserType> userRetrieved = foundObjects.iterator().next(); checkUser(userRetrieved, name, subresult); subresult.recordSuccessIfUnknown(); } catch (SchemaException e) { subresult.recordFatalError(e); return; } catch (RuntimeException e) { subresult.recordFatalError(e); return; } } } finally { try { repositoryService.deleteObject(UserType.class, oid, testResult); } catch (ObjectNotFoundException e) { result.recordFatalError(e); return; } catch (RuntimeException e) { result.recordFatalError(e); return; } result.computeStatus(); } }
private List<ItemWrapper> createProperties(PageBase pageBase) { result = new OperationResult(CREATE_PROPERTIES); List<ItemWrapper> properties = new ArrayList<ItemWrapper>(); PrismContainerDefinition definition = null; PrismObject parent = getObject().getObject(); Class clazz = parent.getCompileTimeClass(); if (ShadowType.class.isAssignableFrom(clazz)) { QName name = containerDefinition.getName(); if (ShadowType.F_ATTRIBUTES.equals(name)) { try { definition = objectWrapper.getRefinedAttributeDefinition(); if (definition == null) { PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF); PrismObject<ResourceType> resource = resourceRef.getValue().getObject(); definition = pageBase .getModelInteractionService() .getEditObjectClassDefinition( (PrismObject<ShadowType>) objectWrapper.getObject(), resource, AuthorizationPhaseType.REQUEST) .toResourceAttributeContainerDefinition(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Refined account def:\n{}", definition.debugDump()); } } } catch (Exception ex) { LoggingUtils.logException( LOGGER, "Couldn't load definitions from refined schema for shadow", ex); result.recordFatalError( "Couldn't load definitions from refined schema for shadow, reason: " + ex.getMessage(), ex); return properties; } } else { definition = containerDefinition; } } else if (ResourceType.class.isAssignableFrom(clazz)) { if (containerDefinition != null) { definition = containerDefinition; } else { definition = container.getDefinition(); } } else { definition = containerDefinition; } if (definition == null) { LOGGER.error( "Couldn't get property list from null definition {}", new Object[] {container.getElementName()}); return properties; } // assignments are treated in a special way -- we display names of // org.units and roles // (but only if ObjectWrapper.isShowAssignments() is true; otherwise // they are filtered out by ObjectWrapper) if (container.getCompileTimeClass() != null && AssignmentType.class.isAssignableFrom(container.getCompileTimeClass())) { for (Object o : container.getValues()) { PrismContainerValue<AssignmentType> pcv = (PrismContainerValue<AssignmentType>) o; AssignmentType assignmentType = pcv.asContainerable(); if (assignmentType.getTargetRef() == null) { continue; } // hack... we want to create a definition for Name // PrismPropertyDefinition def = ((PrismContainerValue) // pcv.getContainer().getParent()).getContainer().findProperty(ObjectType.F_NAME).getDefinition(); PrismPropertyDefinition def = new PrismPropertyDefinition( ObjectType.F_NAME, DOMUtil.XSD_STRING, pcv.getPrismContext()); if (OrgType.COMPLEX_TYPE.equals(assignmentType.getTargetRef().getType())) { def.setDisplayName("Org.Unit"); def.setDisplayOrder(100); } else if (RoleType.COMPLEX_TYPE.equals(assignmentType.getTargetRef().getType())) { def.setDisplayName("Role"); def.setDisplayOrder(200); } else { continue; } PrismProperty<Object> temp = def.instantiate(); String value = formatAssignmentBrief(assignmentType); temp.setValue(new PrismPropertyValue<Object>(value)); // TODO: do this.isReadOnly() - is that OK? (originally it was the default behavior for all // cases) properties.add(new PropertyWrapper(this, temp, this.isReadonly(), ValueStatus.NOT_CHANGED)); } } else if (isShadowAssociation()) { PrismContext prismContext = objectWrapper.getObject().getPrismContext(); Map<QName, PrismContainer<ShadowAssociationType>> assocMap = new HashMap<>(); if (objectWrapper.getAssociations() != null) { for (PrismContainerValue<ShadowAssociationType> cval : objectWrapper.getAssociations()) { ShadowAssociationType associationType = cval.asContainerable(); QName assocName = associationType.getName(); PrismContainer<ShadowAssociationType> fractionalContainer = assocMap.get(assocName); if (fractionalContainer == null) { fractionalContainer = new PrismContainer<>( ShadowType.F_ASSOCIATION, ShadowAssociationType.class, cval.getPrismContext()); fractionalContainer.setDefinition(cval.getParent().getDefinition()); // HACK: set the name of the association as the element name so wrapper.getName() will // return correct data. fractionalContainer.setElementName(assocName); assocMap.put(assocName, fractionalContainer); } try { fractionalContainer.add(cval.clone()); } catch (SchemaException e) { // Should not happen throw new SystemException("Unexpected error: " + e.getMessage(), e); } } } PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF); PrismObject<ResourceType> resource = resourceRef.getValue().getObject(); // HACK. The revive should not be here. Revive is no good. The next use of the resource will // cause parsing of resource schema. We need some centralized place to maintain live cached // copies // of resources. try { resource.revive(prismContext); } catch (SchemaException e) { throw new SystemException(e.getMessage(), e); } RefinedResourceSchema refinedSchema; CompositeRefinedObjectClassDefinition rOcDef; try { refinedSchema = RefinedResourceSchema.getRefinedSchema(resource); rOcDef = refinedSchema.determineCompositeObjectClassDefinition(parent); } catch (SchemaException e) { throw new SystemException(e.getMessage(), e); } // Make sure even empty associations have their wrappers so they can be displayed and edited for (RefinedAssociationDefinition assocDef : rOcDef.getAssociations()) { QName name = assocDef.getName(); if (!assocMap.containsKey(name)) { PrismContainer<ShadowAssociationType> fractionalContainer = new PrismContainer<>( ShadowType.F_ASSOCIATION, ShadowAssociationType.class, prismContext); fractionalContainer.setDefinition(getItemDefinition()); // HACK: set the name of the association as the element name so wrapper.getName() will // return correct data. fractionalContainer.setElementName(name); assocMap.put(name, fractionalContainer); } } for (Entry<QName, PrismContainer<ShadowAssociationType>> assocEntry : assocMap.entrySet()) { // HACK HACK HACK, the container wrapper should not parse itself. This code should not be // here. AssociationWrapper assocWrapper = new AssociationWrapper( this, assocEntry.getValue(), this.isReadonly(), ValueStatus.NOT_CHANGED); properties.add(assocWrapper); } } else { // if not an assignment if ((container.getValues().size() == 1 || container.getValues().isEmpty()) && (containerDefinition == null || containerDefinition.isSingleValue())) { // there's no point in showing properties for non-single-valued // parent containers, // so we continue only if the parent is single-valued Collection<ItemDefinition> propertyDefinitions = definition.getDefinitions(); for (ItemDefinition itemDef : propertyDefinitions) { if (itemDef instanceof PrismPropertyDefinition) { PrismPropertyDefinition def = (PrismPropertyDefinition) itemDef; if (def.isIgnored() || skipProperty(def)) { continue; } if (!showInheritedObjectAttributes && INHERITED_OBJECT_ATTRIBUTES.contains(def.getName())) { continue; } // capability handling for activation properties if (isShadowActivation() && !hasCapability(def)) { continue; } if (isShadowAssociation()) { continue; } PrismProperty property = container.findProperty(def.getName()); boolean propertyIsReadOnly; // decision is based on parent object status, not this // container's one (because container can be added also // to an existing object) if (objectWrapper.getStatus() == ContainerStatus.MODIFYING) { propertyIsReadOnly = !def.canModify(); } else { propertyIsReadOnly = !def.canAdd(); } if (property == null) { properties.add( new PropertyWrapper( this, def.instantiate(), propertyIsReadOnly, ValueStatus.ADDED)); } else { properties.add( new PropertyWrapper(this, property, propertyIsReadOnly, ValueStatus.NOT_CHANGED)); } } else if (itemDef instanceof PrismReferenceDefinition) { PrismReferenceDefinition def = (PrismReferenceDefinition) itemDef; if (INHERITED_OBJECT_ATTRIBUTES.contains(def.getName())) { continue; } PrismReference reference = container.findReference(def.getName()); boolean propertyIsReadOnly; // decision is based on parent object status, not this // container's one (because container can be added also // to an existing object) if (objectWrapper.getStatus() == ContainerStatus.MODIFYING) { propertyIsReadOnly = !def.canModify(); } else { propertyIsReadOnly = !def.canAdd(); } if (reference == null) { properties.add( new ReferenceWrapper( this, def.instantiate(), propertyIsReadOnly, ValueStatus.ADDED)); } else { properties.add( new ReferenceWrapper( this, reference, propertyIsReadOnly, ValueStatus.NOT_CHANGED)); } } } } } Collections.sort(properties, new ItemWrapperComparator()); result.recomputeStatus(); return properties; }
@Override public TaskRunResult run(Task task) { OperationResult result = task.getResult().createSubresult(DOT_CLASS + "run"); TaskRunResult runResult = new TaskRunResult(); LensContextType contextType = task.getModelOperationContext(); if (contextType == null) { LOGGER.trace("No model context found, skipping the model operation execution."); if (result.isUnknown()) { result.computeStatus(); } runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.FINISHED); } else { LensContext context = null; try { context = LensContext.fromLensContextType(contextType, prismContext, provisioningService, result); } catch (SchemaException e) { throw new SystemException( "Cannot recover model context from task " + task + " due to schema exception", e); } catch (ObjectNotFoundException e) { throw new SystemException("Cannot recover model context from task " + task, e); } catch (CommunicationException e) { throw new SystemException( "Cannot recover model context from task " + task, e); // todo wait and retry } catch (ConfigurationException e) { throw new SystemException("Cannot recover model context from task " + task, e); } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Context to be executed = {}", context.debugDump()); } try { // here we brutally remove all the projection contexts -- because if we are continuing after // rejection of a role/resource assignment // that resulted in such projection contexts, we DO NOT want them to appear in the context // any more context.rot(); Iterator<LensProjectionContext> projectionIterator = context.getProjectionContextsIterator(); while (projectionIterator.hasNext()) { LensProjectionContext projectionContext = projectionIterator.next(); if (projectionContext.getPrimaryDelta() != null && !projectionContext.getPrimaryDelta().isEmpty()) { continue; // don't remove client requested actions! } if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Removing projection context {}", projectionContext.getHumanReadableName()); } projectionIterator.remove(); } if (task.getChannel() == null) { task.setChannel(context.getChannel()); } clockwork.run(context, task, result); task.setModelOperationContext(context.toLensContextType()); task.savePendingModifications(result); if (result.isUnknown()) { result.computeStatus(); } runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.FINISHED); } catch (Exception e) { // too many various exceptions; will be fixed with java7 :) String message = "An exception occurred within model operation, in task " + task; LoggingUtils.logException(LOGGER, message, e); result.recordPartialError(message, e); // TODO: here we do not know whether the error is temporary or permanent (in the future we // could discriminate on the basis of particular exception caught) runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.TEMPORARY_ERROR); } } task.getResult().recomputeStatus(); runResult.setOperationResult(task.getResult()); return runResult; }