Skip to content

Commit

Permalink
💥 first attempt to break entity factories, centered around Tags as a …
Browse files Browse the repository at this point in the history
…peripheral use case

Signed-off-by: dseurotech <davide.salvador@eurotech.com>
  • Loading branch information
dseurotech committed Feb 4, 2025
1 parent 81b71f1 commit d3c8f19
Show file tree
Hide file tree
Showing 75 changed files with 602 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
@Deprecated
public abstract class AbstractKapuaConfigurableResourceLimitedService<
E extends KapuaEntity,
C extends KapuaEntityCreator<E>,
C extends KapuaEntityCreator,
S extends KapuaEntityService<E, C>,
F extends KapuaEntityFactory<E>
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @since 1.0
*/
public class ServiceConfigCreator extends KapuaUpdatableEntityCreator<ServiceConfig> {
public class ServiceConfigCreator extends KapuaUpdatableEntityCreator {

private static final long serialVersionUID = 7508550960304732465L;

Expand All @@ -42,7 +42,7 @@ public ServiceConfigCreator(KapuaId scopeId) {
super(scopeId);
}

public ServiceConfigCreator(KapuaEntityCreator<ServiceConfig> entityCreator) {
public ServiceConfigCreator(KapuaEntityCreator entityCreator) {
super(entityCreator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ protected AbstractKapuaUpdatableEntity(KapuaUpdatableEntity entity) {
setModifiedOn(entity.getModifiedOn());
setModifiedBy(entity.getModifiedBy());
setOptlock(entity.getOptlock());
setEntityAttributes(entity.getEntityAttributes());
setEntityProperties(entity.getEntityProperties());
// setEntityAttributes(entity.getEntityAttributes());
// setEntityProperties(entity.getEntityProperties());
}

@Override
Expand Down Expand Up @@ -156,7 +156,7 @@ public void setOptlock(int optlock) {
// Attributes APIs
// -------------------------------------------------

@Override
// @Override
public Properties getEntityAttributes() {
try {
return PropertiesUtils.readPropertiesFromString(attributes);
Expand All @@ -165,7 +165,7 @@ public Properties getEntityAttributes() {
}
}

@Override
// @Override
public void setEntityAttributes(Properties entityAttributes) {
try {
this.attributes = PropertiesUtils.writePropertiesToString(entityAttributes);
Expand All @@ -178,7 +178,7 @@ public void setEntityAttributes(Properties entityAttributes) {
// Properties APIs
// -------------------------------------------------

@Override
// @Override
public Properties getEntityProperties() {
try {
return PropertiesUtils.readPropertiesFromString(properties);
Expand All @@ -187,7 +187,7 @@ public Properties getEntityProperties() {
}
}

@Override
// @Override
public void setEntityProperties(Properties properties) {
try {
this.properties = PropertiesUtils.writePropertiesToString(properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public interface KapuaBaseMapper {
@Mapping(target = "modifiedOn", ignore = true)
@Mapping(target = "modifiedBy", ignore = true)
@Mapping(target = "optlock", ignore = true)
@Mapping(target = "entityProperties", ignore = true)
@IgnoreKapuaEntityReadonlyFields
public @interface IgnoreKapuaUpdatableEntityReadonlyFields {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.eclipse.kapua.model.KapuaEntityCreator;
import org.eclipse.kapua.model.id.KapuaId;

public class EventStoreRecordCreator extends KapuaEntityCreator<EventStoreRecord> {
public class EventStoreRecordCreator extends KapuaEntityCreator {

private static final long serialVersionUID = 1048699703033893534L;

Expand All @@ -26,7 +26,7 @@ public EventStoreRecordCreator(KapuaId scopeId) {
super(scopeId);
}

public EventStoreRecordCreator(KapuaEntityCreator<EventStoreRecord> entityCreator) {
public EventStoreRecordCreator(KapuaEntityCreator entityCreator) {
super(entityCreator);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private KapuaNamedEntityServiceUtils() {
* @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead
*/
@Deprecated
public static <E extends KapuaNamedEntity, C extends KapuaNamedEntityCreator<E>> void checkEntityNameUniqueness(@NotNull KapuaEntityService<E, C> kapuaNamedEntityService, @NotNull C creator)
public static <E extends KapuaNamedEntity, C extends KapuaNamedEntityCreator> void checkEntityNameUniqueness(@NotNull KapuaEntityService<E, C> kapuaNamedEntityService, @NotNull C creator)
throws KapuaException {
checkEntityNameUniqueness(kapuaNamedEntityService, creator, Collections.emptyList());
}
Expand All @@ -98,7 +98,7 @@ public static <E extends KapuaNamedEntity, C extends KapuaNamedEntityCreator<E>>
* @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead
*/
@Deprecated
public static <E extends KapuaNamedEntity, C extends KapuaNamedEntityCreator<E>> void checkEntityNameUniqueness(@NotNull KapuaEntityService<E, C> kapuaNamedEntityService, @NotNull C creator,
public static <E extends KapuaNamedEntity, C extends KapuaNamedEntityCreator> void checkEntityNameUniqueness(@NotNull KapuaEntityService<E, C> kapuaNamedEntityService, @NotNull C creator,
@NotNull List<QueryPredicate> additionalPredicates) throws KapuaException {
KapuaQuery query = new KapuaQuery();
query.setScopeId(creator.getScopeId());
Expand Down Expand Up @@ -196,7 +196,7 @@ public static <E extends KapuaNamedEntity> void checkEntityNameUniqueness(@NotNu
* @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead
*/
@Deprecated
public static <E extends KapuaNamedEntity, C extends KapuaNamedEntityCreator<E>> void checkEntityNameUniquenessInAllScopes(@NotNull KapuaEntityService<E, C> kapuaNamedEntityService,
public static <E extends KapuaNamedEntity, C extends KapuaNamedEntityCreator> void checkEntityNameUniquenessInAllScopes(@NotNull KapuaEntityService<E, C> kapuaNamedEntityService,
@NotNull C creator) throws KapuaException {
KapuaQuery query = new KapuaQuery();
query.setPredicate(query.attributePredicate(KapuaNamedEntityAttributes.NAME, creator.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public AbstractKapuaEntityCreatorTest(BigInteger eid) {
this.eid = eid;
}

private class ActualKapuaEntityCreator<E extends KapuaEntity> extends KapuaEntityCreator<E> {
private class ActualKapuaEntityCreator<E extends KapuaEntity> extends KapuaEntityCreator {

public ActualKapuaEntityCreator(KapuaId scopeId) {
super(scopeId);
}

public ActualKapuaEntityCreator(KapuaEntityCreator<E> abstractEntityCreator) {
public ActualKapuaEntityCreator(KapuaEntityCreator abstractEntityCreator) {
super(abstractEntityCreator);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
*******************************************************************************/
package org.eclipse.kapua.commons.model;

import java.math.BigInteger;
import java.util.Date;
import java.util.Random;

import org.eclipse.kapua.commons.model.id.KapuaEid;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.commons.security.KapuaSession;
Expand All @@ -24,12 +28,6 @@
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;

import java.math.BigInteger;
import java.util.Date;
import java.util.Properties;
import java.util.Random;


@Category(JUnitTests.class)
public class AbstractKapuaUpdatableEntityTest {

Expand Down Expand Up @@ -65,8 +63,8 @@ public void abstractKapuaUpdatableEntityScopeIdTest() {
@Test
public void abstractKapuaUpdatableEntityEntityIdTest() {
KapuaUpdatableEntity entity = new ActualKapuaUpdatableEntity();
entity.setEntityAttributes(new Properties());
entity.setEntityProperties(new Properties());
// entity.setEntityAttributes(new Properties());
// entity.setEntityProperties(new Properties());
entity.setOptlock(10);
AbstractKapuaUpdatableEntity updatableEntity = new ActualKapuaUpdatableEntity(entity);
updatableEntity.setModifiedOn(new Date());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Collection<Object[]> strings() {
});
}

private class ActualKapuaNamedEntityCreator<E extends KapuaEntity> extends KapuaNamedEntityCreator<E> {
private class ActualKapuaNamedEntityCreator<E extends KapuaEntity> extends KapuaNamedEntityCreator {

protected ActualKapuaNamedEntityCreator(KapuaId scopeId, String name) {
super(scopeId, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.Properties;

import org.eclipse.kapua.commons.model.id.KapuaEid;
import org.eclipse.kapua.model.KapuaEntity;
import org.eclipse.kapua.model.KapuaUpdatableEntityCreator;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.qa.markers.junit.JUnitTests;
Expand All @@ -26,7 +25,7 @@
@Category(JUnitTests.class)
public class KapuaUpdatableEntityCreatorTest {

private class ActualKapuaUpdatableEntityCreator<E extends KapuaEntity> extends KapuaUpdatableEntityCreator<E> {
private class ActualKapuaUpdatableEntityCreator extends KapuaUpdatableEntityCreator {

public ActualKapuaUpdatableEntityCreator(KapuaId scopeId) {
super(scopeId);
Expand All @@ -36,14 +35,14 @@ public ActualKapuaUpdatableEntityCreator(KapuaId scopeId) {
@Test
public void abstractKapuaUpdatableEntityCreatorScopeId() {
KapuaId scopeId = new KapuaEid();
KapuaUpdatableEntityCreator<AbstractKapuaEntity> kapuaUpdatableEntityCreator = new ActualKapuaUpdatableEntityCreator<>(scopeId);
KapuaUpdatableEntityCreator kapuaUpdatableEntityCreator = new ActualKapuaUpdatableEntityCreator(scopeId);
Assert.assertEquals("Actual and expected values are not the same!", scopeId, kapuaUpdatableEntityCreator.getScopeId());
}

@Test
public void getEntityAttributesTest() {
KapuaId scopeId = new KapuaEid();
KapuaUpdatableEntityCreator<AbstractKapuaEntity> kapuaUpdatableEntityCreator = new ActualKapuaUpdatableEntityCreator<>(scopeId);
KapuaUpdatableEntityCreator kapuaUpdatableEntityCreator = new ActualKapuaUpdatableEntityCreator(scopeId);
Properties properties = new Properties();
kapuaUpdatableEntityCreator.setEntityAttributes(properties);
Assert.assertEquals("Actual and expected values are not the same!", properties, kapuaUpdatableEntityCreator.getEntityAttributes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@XmlRootElement(name = "queuedJobExecutionCreator")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType
public class QueuedJobExecutionCreator extends KapuaUpdatableEntityCreator<QueuedJobExecution> {
public class QueuedJobExecutionCreator extends KapuaUpdatableEntityCreator {

private static final long serialVersionUID = 3119071638220738358L;

Expand All @@ -45,7 +45,7 @@ public QueuedJobExecutionCreator(KapuaId scopeId) {
super(scopeId);
}

public QueuedJobExecutionCreator(KapuaEntityCreator<QueuedJobExecution> entityCreator) {
public QueuedJobExecutionCreator(KapuaEntityCreator entityCreator) {
super(entityCreator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.eclipse.kapua.service.KapuaService;
import org.eclipse.kapua.service.tag.Tag;
import org.eclipse.kapua.service.tag.TagCreator;
import org.eclipse.kapua.service.tag.TagFactory;
import org.eclipse.kapua.service.tag.TagListResult;
import org.eclipse.kapua.service.tag.TagQuery;
import org.eclipse.kapua.service.tag.TagService;
Expand All @@ -49,8 +48,6 @@ public class Tags extends AbstractKapuaResource {

@Inject
public TagService tagService;
@Inject
public TagFactory tagFactory;

/**
* Gets the {@link Tag} list in the scope.
Expand Down Expand Up @@ -196,7 +193,7 @@ public Tag find(
@PathParam("tagId") EntityId tagId) throws KapuaException {
Tag tag = tagService.find(scopeId, tagId);

return returnNotNullEntity(tag, Tag.TYPE, tagId);
return returnNotNullEntity(tag, "tag", tagId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"organizationCountry",
"expirationDate"
})
public class AccountCreator extends KapuaNamedEntityCreator<Account> {
public class AccountCreator extends KapuaNamedEntityCreator {

private static final long serialVersionUID = -2460883485294616032L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ default Organization createOrganisation() {
void merge(@MappingTarget Organization account, Organization request);

//For backward compatibility only
@Mapping(target = "entityAttributes", ignore = true)
@Mapping(target = "entityProperties", ignore = true)
AccountUpdateRequest mapChildUpdate(Account account);

@Mapping(target = "entityAttributes", ignore = true)
@Mapping(target = "entityProperties", ignore = true)
CurrentAccountUpdateRequest mapCurrentUpdate(Account account);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import javax.inject.Inject;

Expand Down Expand Up @@ -52,7 +51,6 @@

import com.google.inject.Singleton;

import io.cucumber.datatable.DataTable;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;
Expand Down Expand Up @@ -458,26 +456,6 @@ public void findRandomAccountId() throws Exception {
}
}

@When("I set the following parameters")
public void setAccountParameters(DataTable dataTable) throws Exception {
Assert.assertEquals("Wrong test setup. Bad parameters size!", 2, dataTable.width());
Account account = (Account) stepData.get(LAST_ACCOUNT);
Properties accProps = account.getEntityProperties();

for (List<String> row : dataTable.asLists()) {
accProps.setProperty(row.get(0), row.get(1));
}
account.setEntityProperties(accProps);

try {
primeException();
account = accountService.update(account);
stepData.put(LAST_ACCOUNT, account);
} catch (KapuaException ex) {
verifyException(ex);
}
}

@When("I configure {string} item {string} to {string}")
public void setConfigurationValue(String type, String name, String value) throws Exception {
Map<String, Object> valueMap = new HashMap<>();
Expand Down Expand Up @@ -624,17 +602,6 @@ public void findSystemAccount() throws KapuaException {
Assert.assertNotNull(tmpAcc);
}

@Then("The account has the following parameters")
public void checkAccountParameters(DataTable dataTable) throws KapuaException {
Assert.assertEquals("Wrong test setup. Bad parameters size!", 2, dataTable.width());
Account account = (Account) stepData.get(LAST_ACCOUNT);
Properties accProps = account.getEntityProperties();

for (List<String> row : dataTable.asLists()) {
Assert.assertEquals(row.get(1), accProps.getProperty(row.get(0)));
}
}

@Then("The account has metadata")
public void checkMetadataExistence() throws KapuaException {
KapuaId accountId = (KapuaId) stepData.get(LAST_ACCOUNT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,6 @@ Feature: User Account Service
When I delete a random account
Then An exception was thrown

Scenario: Check account properties
It must be possible to set arbitrary account properties.

Given I create a generic account with name "test_acc_11"
When I set the following parameters
| name | value |
| key1 | value1 |
| key2 | value2 |
| key3 | value3 |
Then The account has the following parameters
| name | value |
| key1 | value1 |
| key2 | value2 |
| key3 | value3 |

Scenario: Every account must have the default configuration items
Create a new account and check whether it has the default configuration items set.

Expand Down
Loading

0 comments on commit d3c8f19

Please sign in to comment.