Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Sep 12, 2023
2 parents 0def87d + 55cd7cf commit 35afc96
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected List<QName> getAllowedRelations() {
}

private PrismReferenceDefinition getProjectDefinition() {
return getModelObject().getProjectRefDef();
return getModelObject() != null ? getModelObject().getProjectRefDef() : null;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected List<QName> getAllowedRelations() {
}

public PrismReferenceDefinition getTenantDefinition() {
return getModelObject().getTenantDefinition();
return getModelObject() != null ? getModelObject().getTenantDefinition() : null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import org.apache.wicket.markup.html.form.validation.IFormValidator;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LambdaModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.validation.Validatable;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -111,14 +109,6 @@ protected ObjectType getObjectType() {
};

validator.validate(validatable);
if (!validatable.isValid()) {
validatable.getErrors().forEach(e ->
form.error(e.getErrorMessage((key, vars) ->
new StringResourceModel(key)
.setModel(new Model<String>())
.setDefaultValue(key)
.getString())));
}
}

protected abstract PrismObjectWrapper<O> getObjectWrapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

import org.apache.commons.io.FileUtils;
import org.assertj.core.api.Assertions;
import org.testng.annotations.Test;

Expand All @@ -30,6 +37,55 @@ public class TestMerger extends AbstractSchemaTest {

private static final File TEST_ROOT_DIR = new File("./src/test/resources/merger");

// not commited, contains inital objects for 4.4 and master in separate folders
private static final File TEST_DIR = new File("../../_mess/_init-objects-diff");

@Test(enabled = false)
public <O extends ObjectType> void testInitialObjects() throws Exception {
Map<String, PrismObject<O>> source = loadPrismObjects(new File(TEST_DIR, "master"));
Map<String, PrismObject<O>> target = loadPrismObjects(new File(TEST_DIR, "support-4.4"));

int successCount = 0;
int errorCount = 0;
for (String oid : source.keySet()) {
PrismObject<O> sourceObject = source.get(oid);
PrismObject<O> targetObject = target.get(oid);
if (targetObject == null) {
continue;
}

try {
ObjectMergeOperation.merge(targetObject, sourceObject);
successCount++;
} catch ( Exception ex) {
errorCount++;
ex.printStackTrace();
System.out.println("Couldn't merge object " + sourceObject.toDebugName());
}
}

Assertions.assertThat(errorCount)
.withFailMessage("Successfully merged <%s> objects, <%s> errors", successCount, errorCount)
.isZero();
}

private <O extends ObjectType> Map<String, PrismObject<O>> loadPrismObjects(File dir) {
Map<String, PrismObject<O>> result = new HashMap<>();

Collection<File> files = FileUtils.listFiles(dir, new String[]{"xml"}, true);
files.stream()
.map(f -> {
try {
return (PrismObject) getPrismContext().parseObject(f);
} catch (Exception e) {
throw new IllegalStateException(e);
}
})
.forEach(o -> result.put(o.getOid(), o));

return result;
}

@Test
public void test10LookupTableMergeOperation() throws Exception {
testMergeOperation("lookup-table");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.nio.charset.StandardCharsets;
import java.util.*;

import com.evolveum.midpoint.ninja.util.BasicLightweightIdentifierGenerator;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.FileSystemResource;
Expand Down Expand Up @@ -366,6 +368,7 @@ private PrismObject<TaskType> createRecomputeTask(List<ObjectReferenceType> refs
task.setOid(UUID.randomUUID().toString());
task.setName(new PolyStringType("Initial objects recompute after upgrade to 4.8"));
task.setExecutionState(TaskExecutionStateType.RUNNABLE);
task.setTaskIdentifier(new BasicLightweightIdentifierGenerator().generate().toString());

task.setOwnerRef(new ObjectReferenceType()
.oid(SystemObjectsType.USER_ADMINISTRATOR.value())
Expand Down

0 comments on commit 35afc96

Please sign in to comment.