Skip to content

Commit

Permalink
MID-8842 ninja - mostly comments
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jul 19, 2023
1 parent d9cba62 commit 041e359
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ private void checkOid(ValidationResult result, PrismValue item, String oid) {
} catch (IllegalArgumentException e) {
warn(result, (Item<?, ?>) item.getParent(), "OID '" + oid + "' is not valid UUID");
}

}

private <V extends PrismValue, D extends ItemDefinition<?>> void warn(ValidationResult result, Item<V, D> item, String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,4 @@ default String getIdentifier() {
*/
boolean process(PrismObject<T> object, ItemPath path);

/**
* Matches object type and path template (without container ids in case of multivalue containers.
*
* @param object tested object
* @param path validation item path
* @param type expected type (ObjectType)
* @param expected exptected path template
* @param <O>
* @return true if matches
*/
default <O extends ObjectType> boolean matchObjectTypeAndPathTemplate(PrismObject<?> object, ItemPath path, Class<O> type, ItemPath expected) {
if (!type.isAssignableFrom(object.getCompileTimeClass())) {
return false;
}

if (!path.equivalent(expected)) {
return false;
}

Item item = object.findItem(path);
if (item == null || item.isEmpty()) {
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ private static List<UpgradeObjectProcessor<?>> initProcessors() {
.stream()
.filter(UpgradeObjectProcessor.class::isAssignableFrom)
.filter(c -> !Modifier.isAbstract(c.getModifiers()))

.collect(Collectors.toUnmodifiableSet());

return processors.stream()
Expand All @@ -46,7 +45,7 @@ private static List<UpgradeObjectProcessor<?>> initProcessors() {
throw new IllegalStateException("Processor " + c.getName() + " doesn't have constructor without arguments");
}
})
.sorted(Comparator.comparing(p -> p.getClass().getName()))
.sorted(Comparator.comparing(p -> p.getClass().getName())) // sorting only to ensure deterministic behaviour during object processing
.collect(Collectors.toUnmodifiableList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.evolveum.midpoint.schema.validator.UpgradeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType;

@SuppressWarnings("unused")
public class ApprovalWorkItemsProcessor implements UpgradeObjectProcessor<AssignmentHolderType> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public UpgradeType getType() {

@Override
public boolean isApplicable(PrismObject<?> object, ItemPath path) {
return matchObjectTypeAndPathTemplate(object, path, CaseType.class, ItemPath.create(CaseType.F_TASK_REF));
return matchObjectTypeAndPathTemplate(object, path, CaseType.class, CaseType.F_TASK_REF);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

package com.evolveum.midpoint.schema.validator.processor;

import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessRequestType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AdminGuiConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleCatalogType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

public interface ProcessorMixin {

Expand Down Expand Up @@ -39,4 +39,33 @@ default RoleCatalogType getRoleCatalog(SystemConfigurationType system) {

return roleCatalog;
}

/**
* todo are we really matching only templates?
*
* Matches object type and path template (without container ids in case of multivalue containers).
*
* @param object tested object
* @param path validation item path
* @param type expected type (ObjectType)
* @param expected exptected path template
* @param <O>
* @return true if matches
*/
default <O extends ObjectType> boolean matchObjectTypeAndPathTemplate(PrismObject<?> object, ItemPath path, Class<O> type, ItemPath expected) {
if (!type.isAssignableFrom(object.getCompileTimeClass())) {
return false;
}

if (!path.equivalent(expected)) {
return false;
}

Item item = object.findItem(path);
if (item == null || item.isEmpty()) {
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public void destroy() {

}

/**
* @return target where the log should be printed. In case action result is printed to the standard output, log messages
* should go to the standard error no to mix the output. Otherwise, log messages should go to the standard output.
*/
public LogTarget getLogTarget() {
return LogTarget.SYSTEM_OUT;
}
Expand All @@ -63,6 +67,10 @@ protected void handleResultOnFinish(OperationStatus operation, String finishMess
}
}

/**
* @param allOptions
* @return Level of application context initialization required for this action.
*/
@NotNull
public NinjaApplicationContextLevel getApplicationContextLevel(List<Object> allOptions) {
return NinjaApplicationContextLevel.FULL_REPOSITORY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,29 @@
*/
public enum NinjaApplicationContextLevel {

/**
* No initialization required.
*/
NONE(new String[0]),

/**
* Only midpoint configuration related beans are initialized.
*/
STARTUP_CONFIGURATION(new String[] {
"classpath:ctx-configuration-10-system-init.xml"
}),

/**
* Midpoint configuration and prism related beans are initialized.
*/
NO_REPOSITORY(new String[] {
"classpath:ctx-common.xml",
"classpath:ctx-configuration-no-repo.xml"
}),

/**
* Full repository and audit layer initialization.
*/
FULL_REPOSITORY(new String[] {
"classpath:ctx-common.xml",
"classpath:ctx-configuration.xml",
Expand Down

0 comments on commit 041e359

Please sign in to comment.