Skip to content

Commit

Permalink
Remove TagType support from H2 repository
Browse files Browse the repository at this point in the history
The support is not necessary in 4.7, because we plan to use tags solely
for simulations now (and those will not be supported by generic repo,
either). So it is more efficient to drop preliminary H2 support than
to introduce support for the other databases.

Unrelated change:
 - AbstractTestResource#get now returns a copy of the stored object,
to avoid unintentional modification by the client code.
  • Loading branch information
mederly committed Dec 22, 2022
1 parent f0fa3c9 commit c46b38d
Show file tree
Hide file tree
Showing 25 changed files with 88 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -722,13 +722,6 @@ CREATE TABLE m_system_configuration (
oid VARCHAR(36) NOT NULL,
PRIMARY KEY (oid)
);
CREATE TABLE m_tag (
name_norm VARCHAR(255),
name_orig VARCHAR(255),
uri VARCHAR(255),
oid VARCHAR(36) NOT NULL,
PRIMARY KEY (oid)
);
CREATE TABLE m_trigger (
id INTEGER NOT NULL,
owner_oid VARCHAR(36) NOT NULL,
Expand Down Expand Up @@ -1019,10 +1012,6 @@ CREATE INDEX iSystemConfigurationNameOrig
ON m_system_configuration (name_orig);
ALTER TABLE m_system_configuration
ADD CONSTRAINT uc_system_configuration_name UNIQUE (name_norm);
CREATE INDEX iTagNameOrig
ON m_tag (name_orig);
ALTER TABLE m_tag
ADD CONSTRAINT uc_tag_name UNIQUE (name_norm);
CREATE INDEX iTriggerTimestamp
ON m_trigger (timestampValue);
CREATE INDEX iFullName
Expand Down Expand Up @@ -1211,8 +1200,6 @@ ALTER TABLE m_service
ADD CONSTRAINT fk_service FOREIGN KEY (oid) REFERENCES m_abstract_role;
ALTER TABLE m_system_configuration
ADD CONSTRAINT fk_system_configuration FOREIGN KEY (oid) REFERENCES m_object;
ALTER TABLE m_tag
ADD CONSTRAINT fk_tag FOREIGN KEY (oid) REFERENCES m_object;
ALTER TABLE m_trigger
ADD CONSTRAINT fk_trigger_owner FOREIGN KEY (owner_oid) REFERENCES m_object;
ALTER TABLE m_user
Expand Down
8 changes: 8 additions & 0 deletions config/sql/generic-old/h2-upgrade-4.5-4.6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- resource templates/inheritance
ALTER TABLE m_resource ADD template BOOLEAN;

-- MID-8053: "Active" connectors detection
ALTER TABLE m_connector ADD available BOOLEAN;

-- WRITE CHANGES ABOVE ^^
UPDATE m_global_metadata SET value = '4.6' WHERE name = 'databaseSchemaVersion';
18 changes: 0 additions & 18 deletions config/sql/generic-old/h2-upgrade-4.6-4.7.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ public abstract class DataImport {
protected static final String OPERATION_INITIAL_OBJECTS_IMPORT = DOT_CLASS + "initialObjectsImport";
protected static final String OPERATION_IMPORT_OBJECT = DOT_CLASS + "importObject";

@Autowired
protected PrismContext prismContext;
@Autowired protected PrismContext prismContext;
protected ModelService model;
protected TaskManager taskManager;
@Autowired
protected MidpointConfiguration configuration;
@Autowired protected MidpointConfiguration configuration;

public void setModel(ModelService model) {
Validate.notNull(model, "Model service must not be null.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,20 @@ private ImportResult importObject(PrismObject<? extends ObjectType> object,
String fileName, Task task, OperationResult mainResult, boolean overwrite) {
OperationResult result = mainResult.createSubresult(OPERATION_IMPORT_OBJECT);

Class<? extends ObjectType> type = object.getCompileTimeClass();
if (type == null) {
LOGGER.warn("Object without static type? Skipping: {}", object);
return ImportResult.SKIPPED;
}
if (!model.isSupportedByRepository(type)) { // temporary code (until generic repo is gone)
LOGGER.debug("Skipping {} because of unsupported object type", object);
return ImportResult.SKIPPED;
}

try {
// returns not-null or throws, we don't care about the returned object
model.getObject(
object.getCompileTimeClass(),
type,
object.getOid(),
SelectorOptions.createCollection(GetOperationOptions.createAllowNotFound()),
task,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,4 +625,7 @@ void notifyChange(ResourceObjectShadowChangeDescriptionType changeDescription, T

@NotNull
PrismContext getPrismContext();

/** Returns `true` if the particular object type is supported by the current repository. */
boolean isSupportedByRepository(@NotNull Class<? extends ObjectType> type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class TagManager {
/** Gets a tag by OID. */
public @NotNull TagType getTag(String oid, OperationResult result)
throws ObjectNotFoundException, SchemaException {
if (!cacheRepositoryService.supportsTags()) {
throw new UnsupportedOperationException("The repository does not support tag objects");
}
var options = GetOperationOptionsBuilder.create()
.readOnly()
.build();
Expand All @@ -64,6 +67,9 @@ public class TagManager {
/** Gets a tag by OID (if exists). */
public @Nullable TagType getTagIfExists(String oid, OperationResult result)
throws SchemaException {
if (!cacheRepositoryService.supportsTags()) {
return null;
}
var options = GetOperationOptionsBuilder.create()
.allowNotFound()
.readOnly()
Expand All @@ -83,6 +89,9 @@ public class TagManager {
*/
public @Nullable TagType getTagByUri(@NotNull String uri, OperationResult result)
throws SchemaException, ConfigurationException {
if (!cacheRepositoryService.supportsTags()) {
return null;
}
var tags = cacheRepositoryService.searchObjects(
TagType.class,
prismContext.queryFor(TagType.class)
Expand All @@ -98,6 +107,9 @@ public class TagManager {
}

public @NotNull Collection<TagType> getAllTags(OperationResult result) {
if (!cacheRepositoryService.supportsTags()) {
return List.of();
}
try {
return asObjectables(
cacheRepositoryService.searchObjects(TagType.class, null, null, result));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2364,4 +2364,9 @@ private void computePolyStringVisit(Visitable<?> visitable) {
}
}
}

@Override
public boolean isSupportedByRepository(@NotNull Class<? extends ObjectType> type) {
return cacheRepositoryService.supports(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ public RepositoryDiag getRepositoryDiag() {
return "mock";
}

@Override
public boolean supports(@NotNull Class<? extends ObjectType> type) {
return false;
}

@Override
public void repositorySelfTest(OperationResult parentResult) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ public class AbstractSimulationsTest extends AbstractEmptyModelIntegrationTest {
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);

repoAdd(TAG_USER_ADD, initResult);
repoAdd(TAG_USER_DELETE, initResult);
if (repositoryService.supportsTags()) {
CommonInitialObjects.addTags(this, initResult);
repoAdd(TAG_USER_ADD, initResult);
repoAdd(TAG_USER_DELETE, initResult);
}

repoAdd(ROLE_PERSON, initResult);
repoAdd(ROLE_PERSON_DEV, initResult);
Expand All @@ -96,8 +99,6 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
repoAdd(ARCHETYPE_PERSON_DEV_ARCHETYPE, initResult);
repoAdd(ARCHETYPE_PERSON_DEV_TEMPLATE, initResult);

CommonInitialObjects.addTags(this, initResult);

RESOURCE_SIMPLE_PRODUCTION_TARGET.initAndTest(this, initTask, initResult);
RESOURCE_SIMPLE_DEVELOPMENT_TARGET.initAndTest(this, initTask, initResult);
RESOURCE_SIMPLE_PRODUCTION_SOURCE.initAndTest(this, initTask, initResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public ProcessedObjectAsserter<O, RA> assertType(Class<?> expected) {

@SafeVarargs
public final ProcessedObjectAsserter<O, RA> assertEventTags(AbstractTestResource<TagType>... expectedTags) {
if (!getRepositoryService().supportsTags()) {
return this;
}
Set<String> expectedTagsOids = Arrays.stream(expectedTags)
.map(r -> r.oid)
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,13 @@ default boolean isNative() {
return getRepositoryType().equals("Native");
}

/** Returns `true` if the given object type is supported. */
boolean supports(@NotNull Class<? extends ObjectType> type);

default boolean supportsTags() {
return supports(TagType.class);
}

/**
* Runs a short, non-destructive repository self test.
* This methods should never throw a (checked) exception. All the results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ public <T extends ObjectType> void addDiagnosticInformation(Class<T> type, Strin

//region --- Other methods (delegated directly to repository service) ------------------------------------------

@Override
public boolean supports(@NotNull Class<? extends ObjectType> type) {
return repositoryService.supports(type);
}

@Override
public RepositoryDiag getRepositoryDiag() {
Long startTime = repoOpStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1952,4 +1952,9 @@ private <T extends ObjectType> boolean pruneDiagnosticInformation(
return true;
}
}

@Override
public boolean supports(@NotNull Class<? extends ObjectType> type) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1645,86 +1645,6 @@ public void test544AddNameMetadataUsingReplace() throws Exception {
assertValueMetadataChannel(userAfter, UserType.F_NAME, channel);
}

@Test
public void test560AddModifySearchDeleteTag() throws Exception {
OperationResult result = createOperationResult();

String name = "tag1";
String uri = "http://test.com/tags#tag1";
String uri2 = "http://test.com/tags#tag2";
TagType tag = new TagType()
.name(name)
.uri(uri);

when("tag is added");
String oid = repositoryService.addObject(tag.asPrismObject(), null, result);

when("tag is retrieved by OID");
TagType byOid = repositoryService
.getObject(TagType.class, oid, null, result)
.asObjectable();

then("tag is the same");
displayDumpable("tag retrieved by OID", tag);
PrismAsserts.assertEquivalent(
"tag retrieved by OID differs from the original one", tag.asPrismObject(), byOid.asPrismObject());

when("searching by old URI");
List<PrismObject<TagType>> byUri = repositoryService.searchObjects(
TagType.class,
prismContext.queryFor(TagType.class)
.item(TagType.F_URI).eq(uri)
.build(),
null,
result);

then("there is one matching tag");
displayCollection("tags retrieved by URI", byUri);
assertThat(byUri).as("tags by original uri").hasSize(1);
PrismAsserts.assertEquivalent(
"tag retrieved by URI differs from the original one", tag.asPrismObject(), byUri.get(0));

when("modifying the URI");
repositoryService.modifyObject(
TagType.class,
oid,
prismContext.deltaFor(TagType.class)
.item(TagType.F_URI).replace(uri2)
.asItemDeltas(),
result);

and("searching by new URI");
List<PrismObject<TagType>> byUri2 = repositoryService.searchObjects(
TagType.class,
prismContext.queryFor(TagType.class)
.item(TagType.F_URI).eq(uri2)
.build(),
null,
result);

then("there is one matching tag");
displayCollection("tags retrieved by updated URI", byUri);
assertThat(byUri2).as("tags by original uri").hasSize(1);
tag.setUri(uri2);
PrismAsserts.assertEquivalent(
"tag retrieved by updated URI differs from the expected one", tag.asPrismObject(), byUri2.get(0));

when("tag is deleted");
repositoryService.deleteObject(TagType.class, oid, result);

then("all is OK");
result.computeStatus();
TestUtil.assertSuccess(result);

then("there is no tag by OID");
try {
repositoryService.getObject(TagType.class, oid, null, result);
fail("unexpected success");
} catch (ObjectNotFoundException e) {
displayExpectedException(e);
}
}

private void assertValueMetadataChannel(PrismObject<?> object, ItemName itemName, String expectedValue) {
Item<PrismValue, ItemDefinition> item = object.findItem(itemName);
assertThat(item).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,65 +511,7 @@ public void test018QueryGenericLongTwice() throws Exception {
}

@Test
public void test020QueryTagLong() throws Exception {
Session session = open();
try {

ObjectQuery query = prismContext.queryFor(TagType.class)
.item(F_NAME).eqPoly("tag1")
.and().item(F_EXTENSION, new QName(NS_EXT, "intType")).eq(123)
.build();
String real = getInterpretedQuery(session, TagType.class, query);

assertThat(real).isEqualToIgnoringWhitespace(""
+ "select\n"
+ " _t.oid,\n"
+ " _t.fullObject\n"
+ "from\n"
+ " RTag _t\n"
+ " left join _t.longs _l with (\n"
+ "_l.ownerType = :ownerType and\n"
+ "_l.itemId = :itemId\n"
+ ")\n"
+ "where\n"
+ " (\n"
+ " (\n"
+ " _t.nameCopy.orig = :orig and\n"
+ " _t.nameCopy.norm = :norm\n"
+ " ) and\n"
+ " _l.value = :value\n"
+ " )");

} finally {
close(session);
}
}

@Test
public void test021QueryTagUri() throws Exception {
Session session = open();
try {

ObjectQuery query = prismContext.queryFor(TagType.class)
.item(TagType.F_URI).eq(SchemaConstants.MODEL_POLICY_SITUATION_EXCLUSION_VIOLATION)
.build();
String real = getInterpretedQuery(session, TagType.class, query);

assertThat(real).isEqualToIgnoringWhitespace(""
+ "select\n"
+ " _t.oid,\n"
+ " _t.fullObject\n"
+ "from\n"
+ " RTag _t\n"
+ "where\n"
+ " _t.uri = :uri");
} finally {
close(session);
}
}

@Test
public void test029QueryAccountByNonExistingAttribute() throws Exception {
public void test019QueryAccountByNonExistingAttribute() throws Exception {
Session session = open();
try {
String real = getInterpretedQuery(session, ShadowType.class,
Expand Down

0 comments on commit c46b38d

Please sign in to comment.