Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
* 'master' of github.com:Evolveum/midpoint:
  Add "evaluateExpression" bulk action
  Make TestUtil#CHECK_RESULTS final
  Revert change to TestUtils
  Updated database to store ActivityAffectedObjects
  Resolve merge conflicts
  Prepare scripting/library execution profiles
  Fix "affected objects" schema
  Add task "affected objects" computation
  • Loading branch information
katkav committed Aug 7, 2023
2 parents 1041cb9 + e102f53 commit 49f55e5
Show file tree
Hide file tree
Showing 216 changed files with 4,650 additions and 1,933 deletions.
60 changes: 31 additions & 29 deletions config/sql/native-new/postgres-new-upgrade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -325,38 +325,12 @@ $aa$);

-- Task Affected Indexing (Changes to types)
call apply_change(16, $aa$
ALTER TYPE ContainerType ADD VALUE IF NOT EXISTS 'AFFECTED_RESOURCE_OBJECTS' AFTER 'ACCESS_CERTIFICATION_WORK_ITEM';
ALTER TYPE ContainerType ADD VALUE IF NOT EXISTS 'AFFECTED_OBJECTS' AFTER 'AFFECTED_RESOURCE_OBJECTS';
ALTER TYPE ContainerType ADD VALUE IF NOT EXISTS 'AFFECTED_OBJECTS' AFTER 'ACCESS_CERTIFICATION_WORK_ITEM';
$aa$);

-- Task Affected Indexing (tables)

call apply_change(17, $aa$
CREATE TABLE m_task_affected_resource_objects (
ownerOid UUID NOT NULL REFERENCES m_object_oid(oid) ON DELETE CASCADE,
containerType ContainerType GENERATED ALWAYS AS ('AFFECTED_RESOURCE_OBJECTS') STORED
CHECK (containerType = 'AFFECTED_RESOURCE_OBJECTS'),
objectClassId INTEGER REFERENCES m_uri(id),
resourceRefTargetOid UUID,
resourceRefTargetType ObjectType,
resourceRefRelationId INTEGER REFERENCES m_uri(id),
intent TEXT,
kind ShadowKindType,
PRIMARY KEY (ownerOid, cid)
) INHERITS(m_container);

CREATE TABLE m_task_affected_objects (
ownerOid UUID NOT NULL REFERENCES m_object_oid(oid) ON DELETE CASCADE,
containerType ContainerType GENERATED ALWAYS AS ('AFFECTED_OBJECTS') STORED
CHECK (containerType = 'AFFECTED_OBJECTS'),
type ObjectType,
archetypeRefTargetOid UUID,
archetypeRefTargetType ObjectType,
archetypeRefRelationId INTEGER REFERENCES m_uri(id),
PRIMARY KEY (ownerOid, cid)
) INHERITS(m_container);
-- Task Affected Indexing (tables), empty now, replaced with change 19

$aa$);
call apply_change(17, $$ SELECT 1 $$, true);


-- Resource/super/resourceRef Indexing (tables)
Expand All @@ -366,6 +340,34 @@ ADD COLUMN superRefTargetOid UUID,
ADD COLUMN superRefTargetType ObjectType,
ADD COLUMN superRefRelationId INTEGER REFERENCES m_uri(id);
$aa$)

-- Fixed upgrade for task indexing
-- Drop tables should only affect development machines
call apply_change(19, $aa$
DROP TABLE IF EXISTS m_task_affected_resource_objects;
DROP TABLE IF EXISTS m_task_affected_objects;

CREATE TABLE m_task_affected_objects (
ownerOid UUID NOT NULL REFERENCES m_object_oid(oid) ON DELETE CASCADE,
containerType ContainerType GENERATED ALWAYS AS ('AFFECTED_OBJECTS') STORED
CHECK (containerType = 'AFFECTED_OBJECTS'),
activityId INTEGER REFERENCES m_uri(id),
type ObjectType,
archetypeRefTargetOid UUID,
archetypeRefTargetType ObjectType,
archetypeRefRelationId INTEGER REFERENCES m_uri(id),
objectClassId INTEGER REFERENCES m_uri(id),
resourceRefTargetOid UUID,
resourceRefTargetType ObjectType,
resourceRefRelationId INTEGER REFERENCES m_uri(id),
intent TEXT,
kind ShadowKindType,
PRIMARY KEY (ownerOid, cid)
) INHERITS(m_container);

$aa$)


---
-- WRITE CHANGES ABOVE ^^
-- IMPORTANT: update apply_change number at the end of postgres-new.sql
Expand Down
39 changes: 17 additions & 22 deletions config/sql/native-new/postgres-new.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ CREATE EXTENSION IF NOT EXISTS fuzzystrmatch; -- fuzzy string match (levenshtein
CREATE TYPE ContainerType AS ENUM (
'ACCESS_CERTIFICATION_CASE',
'ACCESS_CERTIFICATION_WORK_ITEM',
'AFFECTED_OBJECTS',
'ASSIGNMENT',
'CASE_WORK_ITEM',
'FOCUS_IDENTITY',
Expand Down Expand Up @@ -1312,28 +1313,22 @@ CREATE INDEX m_task_fullTextInfo_idx ON m_task USING gin(fullTextInfo gin_trgm_o
CREATE INDEX m_task_createTimestamp_idx ON m_task (createTimestamp);
CREATE INDEX m_task_modifyTimestamp_idx ON m_task (modifyTimestamp);

CREATE TABLE m_task_affected_resource_objects (
ownerOid UUID NOT NULL REFERENCES m_object_oid(oid) ON DELETE CASCADE,
containerType ContainerType GENERATED ALWAYS AS ('AFFECTED_RESOURCE_OBJECTS') STORED
CHECK (containerType = 'AFFECTED_RESOURCE_OBJECTS'),
objectClassId INTEGER REFERENCES m_uri(id),
resourceRefTargetOid UUID,
resourceRefTargetType ObjectType,
resourceRefRelationId INTEGER REFERENCES m_uri(id),
intent TEXT,
kind ShadowKindType,
PRIMARY KEY (ownerOid, cid)
) INHERITS(m_container);

CREATE TABLE m_task_affected_objects (
ownerOid UUID NOT NULL REFERENCES m_object_oid(oid) ON DELETE CASCADE,
containerType ContainerType GENERATED ALWAYS AS ('AFFECTED_OBJECTS') STORED
CHECK (containerType = 'AFFECTED_OBJECTS'),
type ObjectType,
archetypeRefTargetOid UUID,
archetypeRefTargetType ObjectType,
archetypeRefRelationId INTEGER REFERENCES m_uri(id),
PRIMARY KEY (ownerOid, cid)
ownerOid UUID NOT NULL REFERENCES m_object_oid(oid) ON DELETE CASCADE,
containerType ContainerType GENERATED ALWAYS AS ('AFFECTED_OBJECTS') STORED
CHECK (containerType = 'AFFECTED_OBJECTS'),
activityId INTEGER REFERENCES m_uri(id),
type ObjectType,
archetypeRefTargetOid UUID,
archetypeRefTargetType ObjectType,
archetypeRefRelationId INTEGER REFERENCES m_uri(id),
objectClassId INTEGER REFERENCES m_uri(id),
resourceRefTargetOid UUID,
resourceRefTargetType ObjectType,
resourceRefRelationId INTEGER REFERENCES m_uri(id),
intent TEXT,
kind ShadowKindType,
PRIMARY KEY (ownerOid, cid)
) INHERITS(m_container);

-- endregion
Expand Down Expand Up @@ -2115,4 +2110,4 @@ END $$;
-- This is important to avoid applying any change more than once.
-- Also update SqaleUtils.CURRENT_SCHEMA_CHANGE_NUMBER
-- repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/SqaleUtils.java
call apply_change(18, $$ SELECT 1 $$, true);
call apply_change(19, $$ SELECT 1 $$, true);
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import java.io.File;
import java.util.Arrays;

import com.evolveum.midpoint.schema.config.ConfigurationItemOrigin;
import com.evolveum.midpoint.schema.config.ExecuteScriptConfigItem;
import com.evolveum.midpoint.schema.util.ScriptingBeansUtil;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.Validate;
Expand Down Expand Up @@ -146,15 +150,24 @@ private boolean executeScript(PrismProperty<Object> expression, File file, Task

try {
LOGGER.info("Starting post-initial execute script from file {}.", file.getName());
Object parsed = expression.getAnyValue().getValue();
ExecuteScriptType parsed =
ScriptingBeansUtil.asExecuteScriptCommand(
expression.getAnyValue().getValue());

ScriptExecutionResult executionResult =
parsed instanceof ExecuteScriptType ?
scripting.evaluateExpression((ExecuteScriptType) parsed, VariablesMap.emptyMap(),
false, task, result) :
scripting.evaluateExpression((ScriptingExpressionType) parsed, task, result);
scripting.evaluateExpression(
ExecuteScriptConfigItem.of(
parsed,
// TODO or should we create some "fully trusted origin"?
ConfigurationItemOrigin.external(SchemaConstants.CHANNEL_INIT_URI)),
VariablesMap.emptyMap(),
false,
task,
result);
result.recordSuccess();
result.addReturn("console", executionResult.getConsoleOutput());
LOGGER.info("Executed a script in {} as part of post-initial import. Output is:\n{}", file.getName(), executionResult.getConsoleOutput());
LOGGER.info("Executed a script in {} as part of post-initial import. Output is:\n{}",
file.getName(), executionResult.getConsoleOutput());
return true;
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute script from file {}", ex, file.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import com.evolveum.midpoint.authentication.api.util.AuthConstants;
import com.evolveum.midpoint.authentication.api.authorization.Url;

import com.evolveum.midpoint.schema.config.ConfigurationItemOrigin;
import com.evolveum.midpoint.schema.config.ExecuteScriptConfigItem;
import com.evolveum.midpoint.schema.util.ScriptingBeansUtil;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.CheckBox;
Expand Down Expand Up @@ -105,43 +109,57 @@ private void startPerformed(AjaxRequestTarget target) {
return;
}

Object parsed = null;
ExecuteScriptType typed = null;
try {
parsed = getPrismContext().parserFor(bulkActionDto.getScript()).parseRealValue();
Object parsed = getPrismContext().parserFor(bulkActionDto.getScript()).parseRealValue();
if (parsed == null) {
result.recordFatalError(createStringResource("PageBulkAction.message.startPerformed.fatalError.provided").getString());
result.recordFatalError(
createStringResource("PageBulkAction.message.startPerformed.fatalError.provided").getString());
} else if (!(parsed instanceof ExecuteScriptType) && !(parsed instanceof ScriptingExpressionType)) {
result.recordFatalError(createStringResource("PageBulkAction.message.startPerformed.fatalError.notBulkAction", "{scripting-3}ScriptingExpressionType", parsed.getClass()).getString());
result.recordFatalError(
createStringResource(
"PageBulkAction.message.startPerformed.fatalError.notBulkAction",
"{scripting-3}ExecuteScriptType",
"{scripting-3}ScriptingExpressionType",
parsed.getClass()).getString());
} else {
typed = ScriptingBeansUtil.asExecuteScriptCommand(parsed);
}
} catch (SchemaException | RuntimeException e) {
result.recordFatalError(createStringResource("PageBulkAction.message.startPerformed.fatalError.parse").getString(), e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't parse bulk action object", e);
}

if (parsed != null) {
if (typed != null) {
if (bulkActionDto.isAsync()) {
try {
if (parsed instanceof ExecuteScriptType) {
getScriptingService().evaluateExpressionInBackground((ExecuteScriptType) parsed, task, result);
} else {
//noinspection ConstantConditions
getScriptingService().evaluateExpressionInBackground((ScriptingExpressionType) parsed, task, result);
}
result.recordStatus(OperationResultStatus.IN_PROGRESS, createStringResource("PageBulkAction.message.startPerformed.inProgress", task.getName()).getString());
} catch (SchemaException | SecurityViolationException | ExpressionEvaluationException | ObjectNotFoundException
| CommunicationException | ConfigurationException | ClassCastException e) {
result.recordFatalError(createStringResource("PageBulkAction.message.startPerformed.fatalError.submit").getString(), e);
getModelInteractionService().submitScriptingExpression(typed, task, result);
result.recordStatus(
OperationResultStatus.IN_PROGRESS,
createStringResource(
"PageBulkAction.message.startPerformed.inProgress",
task.getName()).getString());
} catch (CommonException | ClassCastException e) {
result.recordFatalError(
createStringResource(
"PageBulkAction.message.startPerformed.fatalError.submit").getString(), e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't submit bulk action to execution", e);
}
} else {
try {
//noinspection ConstantConditions
ScriptExecutionResult executionResult =
parsed instanceof ExecuteScriptType ?
getScriptingService().evaluateExpression((ExecuteScriptType) parsed, VariablesMap.emptyMap(),
false, task, result) :
getScriptingService().evaluateExpression((ScriptingExpressionType) parsed, task, result);
result.recordStatus(OperationResultStatus.SUCCESS, createStringResource("PageBulkAction.message.startPerformed.success", executionResult.getDataOutput().size()).getString());
getScriptingService().evaluateExpression(
ExecuteScriptConfigItem.of(typed, ConfigurationItemOrigin.user()),
VariablesMap.emptyMap(),
false,
task,
result);
result.recordStatus(
OperationResultStatus.SUCCESS,
createStringResource(
"PageBulkAction.message.startPerformed.success",
executionResult.getDataOutput().size()).getString());
result.addReturn("console", executionResult.getConsoleOutput());
result.addArbitraryObjectCollectionAsReturn("data", executionResult.getDataOutput());
} catch (ScriptExecutionException | SchemaException | SecurityViolationException | ExpressionEvaluationException
Expand Down

0 comments on commit 49f55e5

Please sign in to comment.