diff --git a/keywi/api/src/main/java/com/devonfw/keywi/general/common/api/to/AbstractSearchCriteriaTo.java b/keywi/api/src/main/java/com/devonfw/keywi/general/common/api/to/AbstractSearchCriteriaTo.java new file mode 100644 index 0000000..0eabae6 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/keywi/general/common/api/to/AbstractSearchCriteriaTo.java @@ -0,0 +1,32 @@ +package com.devonfw.keywi.general.common.api.to; + +import org.springframework.data.domain.Pageable; + +import com.devonfw.module.basic.common.api.to.AbstractTo; + +/** + * Abstract {@link AbstractTo TO} for search criteria. + */ +public abstract class AbstractSearchCriteriaTo extends AbstractTo { + + private static final long serialVersionUID = 1L; + + private Pageable pageable; + + /** + * @return the {@link Pageable} containing the optional pagination information or {@code null}. + */ + public Pageable getPageable() { + + return this.pageable; + } + + /** + * @param pageable new value of {@link #getPageable()}. + */ + public void setPageable(Pageable pageable) { + + this.pageable = pageable; + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/common/api/KeyItem.java b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/common/api/KeyItem.java new file mode 100644 index 0000000..32a1268 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/common/api/KeyItem.java @@ -0,0 +1,38 @@ +package com.devonfw.keywi.keymanagement.common.api; + +import com.devonfw.module.basic.common.api.reference.IdRef; + +/** + * Interface for an item of an {@link #getKeyListId() owning} {@link KeyList}. + */ +public interface KeyItem extends KeyObject { + + /** Property name for {@link #getValue()}. */ + String PROPERTY_VALUE = "value"; + + /** Column name for {@link #getValue()}. */ + String COLUMN_VALUE = "value"; + + /** + * @return the optional value of this item. May be {@code null}. + * @see KeyList#isValueRequired() + * @see KeyList#getValuePattern() + */ + String getValue(); + + /** + * @param value new value of {@link #getValue()}. + */ + void setValue(String value); + + /** + * @return the {@link IdRef} pointing to the {@link KeyList} owning this item. + */ + IdRef getKeyListId(); + + /** + * @param keyListId new value of {@link #getKeyListId()}. + */ + void setKeyListId(IdRef keyListId); + +} diff --git a/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/common/api/KeyList.java b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/common/api/KeyList.java new file mode 100644 index 0000000..5511ad9 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/common/api/KeyList.java @@ -0,0 +1,78 @@ +package com.devonfw.keywi.keymanagement.common.api; + +import java.util.regex.Pattern; + +import com.devonfw.keywi.keymanagement.dataaccess.api.datatype.KeyItemProperty; + +/** + * Interface for a list of {@link KeyItem}s. + */ +public interface KeyList extends KeyObject { + + /** + * @return {@code true} if the {@link KeyItem#getKeyListId() containing} {@link KeyItem}s shall be cached by clients, + * {@code false} otherwise. A {@link KeyList} with up to {@code 100} {@link KeyItem}s should always be cached + * while lists with more than {@code 10.000} {@link KeyItem}s should never be cached. + */ + boolean isCacheable(); + + /** + * @param cacheable new value of {@link #isCacheable()}. Changing will have complex implications and should be + * considered with care. + */ + void setCacheable(boolean cacheable); + + /** + * @return the {@link KeyItemProperty property} to sort the {@link KeyItem}s by default. Defaults to + * {@link KeyItemProperty#NAME} and may not be {@code null}. + */ + KeyItemProperty getOrdering(); + + /** + * @param ordering new value of {@link #getOrdering()}. May not be {@code null}. + */ + void setOrdering(KeyItemProperty ordering); + + /** + * @return {@code true} if the {@link KeyItem#getValue() value} of the {@link KeyItem#getKeyListId() owned} + * {@link KeyItem}s is required and may not be {@code null} or {@link String#isEmpty() empty}, {@code false} + * otherwise (if it is optional and may be {@code null}). + * @see #getValuePattern() + */ + boolean isValueRequired(); + + /** + * @param valueRequired new value of {@link #isValueRequired()}. Please note that changing this value to {@code true} + * can make existing {@link KeyItem}s in database invalid. + */ + void setValueRequired(boolean valueRequired); + + /** + * @return the optional regular expression {@link Pattern} the {@link KeyItem#getValue() values} of + * {@link KeyItem#getKeyListId() owned} {@link KeyItem}s have to match if they are not empty. May be + * {@code null} if any value is considered valid. + * @see #isValueRequired() + */ + Pattern getValuePattern(); + + /** + * @param valuePattern new value of {@link #getValuePattern()}. Please note that changing this value can make existing + * {@link KeyItem}s in database invalid. + */ + void setValuePattern(Pattern valuePattern); + + /** + * @return the identifier of the additional permission required to manage this {@link KeyList} and its + * {@link KeyItem}s. Then to save or even delete a {@link KeyItem} {@link KeyItem#getKeyListId() owned} by + * this {@link KeyList} will additionally require that the user has the specified permission. Please note that + * reading {@link KeyItem}s is not affected by this permission. May be {@code null} to only require standard + * permissions. + */ + String getPermission(); + + /** + * @param permission new value of {@link #getPermission()}. + */ + void setPermission(String permission); + +} diff --git a/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/common/api/KeyObject.java b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/common/api/KeyObject.java new file mode 100644 index 0000000..df91cd9 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/common/api/KeyObject.java @@ -0,0 +1,70 @@ +package com.devonfw.keywi.keymanagement.common.api; + +import com.devonfw.keywi.general.common.api.ApplicationEntity; + +/** + * Interface for item of + */ +public interface KeyObject extends ApplicationEntity { + + /** Property name for {@link #getKey()}. */ + String PROPERTY_KEY = "key"; + + /** Column name for {@link #getKey()}. */ + String COLUMN_KEY = "business_key"; + + /** Property name for {@link #getName()}. */ + String PROPERTY_NAME = "name"; + + /** Column name for {@link #getName()}. */ + String COLUMN_NAME = "name"; + + /** Property name for {@link #getComment()}. */ + String PROPERTY_COMMENT = "comment"; + + /** Column name for {@link #getComment()}. */ + String COLUMN_COMMENT = "comment"; + + /** + * @return keyId + */ + String getKey(); + + /** + * @param key setter for key attribute + */ + void setKey(String key); + + /** + * @return nameId + */ + String getName(); + + /** + * @param name setter for name attribute + */ + void setName(String name); + + /** + * @return descriptionId + */ + String getComment(); + + /** + * @param description setter for description attribute + */ + void setComment(String description); + + /** + * @return {@code true} if this item is disabled (deprecated) and may not be selected anymore. It can still be loaded + * and displayed but it should not be available anymore for selection and should be considered as invalid when + * saving data. Regular items are called active and will return {@code false} here. + */ + boolean isDisabled(); + + /** + * @param disabled new value of {@link #isDisabled()}. + */ + void setDisabled(boolean disabled); + +} diff --git a/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/datatype/KeyItemProperty.java b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/datatype/KeyItemProperty.java new file mode 100644 index 0000000..4ba5c7d --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/datatype/KeyItemProperty.java @@ -0,0 +1,54 @@ +package com.devonfw.keywi.keymanagement.dataaccess.api.datatype; + +import com.devonfw.keywi.keymanagement.common.api.KeyItem; +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.keywi.keymanagement.common.api.KeyObject; + +/** + * Enum with the properties of a {@link KeyItem}. + * + * @see KeyList#getOrdering() + * + * @since 1.0.0 + */ +public enum KeyItemProperty { + + /** {@link KeyItemProperty} for {@link KeyObject#getName()}. */ + NAME(KeyObject.PROPERTY_NAME, KeyObject.COLUMN_NAME), + + /** {@link KeyItemProperty} for {@link KeyObject#getKey()}. */ + KEY(KeyObject.PROPERTY_KEY, KeyObject.COLUMN_KEY), + + /** {@link KeyItemProperty} for {@link KeyObject#getComment()}. */ + COMMENT(KeyObject.PROPERTY_COMMENT, KeyObject.COLUMN_COMMENT), + + /** {@link KeyItemProperty} for {@link KeyItem#getName()}. */ + VALUE(KeyItem.PROPERTY_VALUE, KeyItem.COLUMN_VALUE); + + private final String columnName; + + private final String propertyName; + + private KeyItemProperty(String fieldName, String columnName) { + + this.propertyName = fieldName; + this.columnName = columnName; + } + + /** + * @return the Java property name (e.g. "key" for "getKey()"). + */ + public String getPropertyName() { + + return this.propertyName; + } + + /** + * @return the {@link javax.persistence.Column#name() column name} in the database. + */ + public String getColumnName() { + + return this.columnName; + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/logic/api/to/KeyItemEto.java b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/logic/api/to/KeyItemEto.java new file mode 100644 index 0000000..acd515a --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/logic/api/to/KeyItemEto.java @@ -0,0 +1,72 @@ +package com.devonfw.keywi.keymanagement.logic.api.to; + +import java.util.Objects; + +import com.devonfw.keywi.keymanagement.common.api.KeyItem; +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.module.basic.common.api.reference.IdRef; + +/** + * {@link com.devonfw.module.basic.common.api.to.AbstractEto ETO} for {@link KeyItem}. + */ +public class KeyItemEto extends KeyObjectEto implements KeyItem { + + private static final long serialVersionUID = 1L; + + private String value; + + private IdRef keyListId; + + @Override + public String getValue() { + + return this.value; + } + + @Override + public void setValue(String value) { + + this.value = value; + } + + @Override + public IdRef getKeyListId() { + + return this.keyListId; + } + + @Override + public void setKeyListId(IdRef keyListId) { + + this.keyListId = keyListId; + } + + @Override + public int hashCode() { + + return Objects.hash(super.hashCode(), this.keyListId, this.value); + } + + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + // class check will be done by super type EntityTo! + if (!super.equals(obj)) { + return false; + } + KeyItemEto other = (KeyItemEto) obj; + if (!Objects.equals(this.keyListId, other.keyListId)) { + return false; + } else if (!Objects.equals(this.value, other.value)) { + return false; + } + return true; + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/logic/api/to/KeyItemSearchCriteriaTo.java b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/logic/api/to/KeyItemSearchCriteriaTo.java new file mode 100644 index 0000000..847c891 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/logic/api/to/KeyItemSearchCriteriaTo.java @@ -0,0 +1,93 @@ +package com.devonfw.keywi.keymanagement.logic.api.to; + +import com.devonfw.keywi.general.common.api.to.AbstractSearchCriteriaTo; +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.keywi.keymanagement.dataaccess.api.datatype.KeyItemProperty; +import com.devonfw.module.basic.common.api.reference.IdRef; +import com.devonfw.module.criteria.common.api.query.StringSearchCriteria; + +/** + * {@link AbstractSearchCriteriaTo Search criteria} to find {@link KeyItemEto}s. + * + * @since 1.0.0 + */ +public class KeyItemSearchCriteriaTo extends AbstractSearchCriteriaTo { + + private static final long serialVersionUID = 1L; + + private IdRef keyListId; + + private boolean activeOnly; + + private KeyItemProperty ordering; + + private StringSearchCriteria name; + + /** + * @return keyListId the {@link IdRef} pointing to the {@link KeyList} + * {@link com.devonfw.keywi.keymanagement.common.api.KeyItem#getKeyListId() owning} this item. Shall not be + * {@code null}. + */ + public IdRef getKeyListId() { + + return this.keyListId; + } + + /** + * @param keyListId new value of {@link #getKeyListId()}. + */ + public void setKeyListId(IdRef keyListId) { + + this.keyListId = keyListId; + } + + /** + * @return activeOnly + */ + public boolean isActiveOnly() { + + return this.activeOnly; + } + + /** + * @param activeOnly new value of {@link #isActiveOnly()}. + */ + public void setActiveOnly(boolean activeOnly) { + + this.activeOnly = activeOnly; + } + + /** + * @return ordering the explicit {@link KeyList#getOrdering() ordering} or {@code null} to use + * {@link KeyList#getOrdering() default}. + */ + public KeyItemProperty getOrdering() { + + return this.ordering; + } + + /** + * @param ordering new value of {@link #getOrdering()}. + */ + public void setOrdering(KeyItemProperty ordering) { + + this.ordering = ordering; + } + + /** + * @return name {@link StringSearchCriteria} for {@link KeyItemEto#getName() name}. + */ + public StringSearchCriteria getName() { + + return this.name; + } + + /** + * @param name new value of {@link #getName()}. + */ + public void setName(StringSearchCriteria name) { + + this.name = name; + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/logic/api/to/KeyListEto.java b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/logic/api/to/KeyListEto.java new file mode 100644 index 0000000..e0bc193 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/logic/api/to/KeyListEto.java @@ -0,0 +1,127 @@ +package com.devonfw.keywi.keymanagement.logic.api.to; + +import java.util.Objects; +import java.util.regex.Pattern; + +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.keywi.keymanagement.dataaccess.api.datatype.KeyItemProperty; + +/** + * {@link com.devonfw.module.basic.common.api.to.AbstractEto ETO} for {@link KeyList}. + */ +public class KeyListEto extends KeyObjectEto implements KeyList { + + private static final long serialVersionUID = 1L; + + private KeyItemProperty ordering; + + private boolean valueRequired; + + private Pattern valuePattern; + + private String permission; + + private boolean cacheable; + + /** + * The constructor. + */ + public KeyListEto() { + + super(); + this.ordering = KeyItemProperty.NAME; + } + + @Override + public KeyItemProperty getOrdering() { + + return this.ordering; + } + + @Override + public void setOrdering(KeyItemProperty ordering) { + + Objects.requireNonNull(ordering, "ordering"); + this.ordering = ordering; + } + + @Override + public boolean isValueRequired() { + + return this.valueRequired; + } + + @Override + public void setValueRequired(boolean valueRequired) { + + this.valueRequired = valueRequired; + } + + @Override + public Pattern getValuePattern() { + + return this.valuePattern; + } + + @Override + public void setValuePattern(Pattern valuePattern) { + + this.valuePattern = valuePattern; + } + + @Override + public String getPermission() { + + return this.permission; + } + + @Override + public void setPermission(String permission) { + + this.permission = permission; + } + + @Override + public boolean isCacheable() { + + return this.cacheable; + } + + @Override + public void setCacheable(boolean cacheable) { + + this.cacheable = cacheable; + } + + @Override + public int hashCode() { + + return Objects.hash(super.hashCode(), this.valuePattern, this.valueRequired, this.permission, this.cacheable); + } + + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + // class check will be done by super type EntityTo! + if (!super.equals(obj)) { + return false; + } + KeyListEto other = (KeyListEto) obj; + if (this.valueRequired != other.valueRequired) { + return false; + } else if (this.cacheable != other.cacheable) { + return false; + } else if (!Objects.equals(this.valuePattern, other.valuePattern)) { + return false; + } else if (!Objects.equals(this.permission, other.permission)) { + return false; + } + return true; + } +} diff --git a/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/logic/api/to/KeyObjectEto.java b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/logic/api/to/KeyObjectEto.java new file mode 100644 index 0000000..ca85eca --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/logic/api/to/KeyObjectEto.java @@ -0,0 +1,103 @@ +package com.devonfw.keywi.keymanagement.logic.api.to; + +import java.util.Objects; + +import com.devonfw.keywi.keymanagement.common.api.KeyObject; +import com.devonfw.module.basic.common.api.to.AbstractEto; + +/** + * {@link AbstractEto ETO} for {@link KeyObject}. + */ +public abstract class KeyObjectEto extends AbstractEto implements KeyObject { + + private static final long serialVersionUID = 1L; + + private String key; + + private String name; + + private String comment; + + private boolean disabled; + + @Override + public String getKey() { + + return this.key; + } + + @Override + public void setKey(String key) { + + this.key = key; + } + + @Override + public String getName() { + + return this.name; + } + + @Override + public void setName(String name) { + + this.name = name; + } + + @Override + public String getComment() { + + return this.comment; + } + + @Override + public void setComment(String comment) { + + this.comment = comment; + } + + @Override + public boolean isDisabled() { + + return this.disabled; + } + + @Override + public void setDisabled(boolean disabled) { + + this.disabled = disabled; + } + + @Override + public int hashCode() { + + return Objects.hash(this.key, this.name, this.comment, this.disabled); + } + + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + // class check will be done by super type EntityTo! + if (!super.equals(obj)) { + return false; + } + KeyObjectEto other = (KeyObjectEto) obj; + if (this.disabled != other.disabled) { + return false; + } else if (!Objects.equals(this.key, other.key)) { + return false; + } else if (!Objects.equals(this.name, other.name)) { + return false; + } else if (!Objects.equals(this.comment, other.comment)) { + return false; + } + return true; + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/service/api/rest/KeymanagementRestService.java b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/service/api/rest/KeymanagementRestService.java new file mode 100644 index 0000000..e84cf09 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/keywi/keymanagement/service/api/rest/KeymanagementRestService.java @@ -0,0 +1,97 @@ +package com.devonfw.keywi.keymanagement.service.api.rest; + +import java.util.List; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +import org.springframework.data.domain.Page; + +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyItemEto; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyItemSearchCriteriaTo; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyListEto; +import com.devonfw.module.rest.common.api.RestService; + +/** + * The service interface for REST calls in order to execute the logic of component Keymanagement. + */ +@Path("/keymanagement/v1") +public interface KeymanagementRestService extends RestService { + + /** + * @return the {@link List} of all {@link KeyListEto}. + */ + List findKeyListEtos(); + + /** + * @param id the ID of the {@link KeyListEto} + * @return the {@link KeyListEto} + */ + @GET + @Path("/keylist/{id}/") + KeyListEto findKeyList(@PathParam("id") long id); + + /** + * @param keylist the {@link KeyListEto} to be saved + * @return the recently created {@link KeyListEto} + */ + @POST + @Path("/keylist/") + KeyListEto saveKeyList(KeyListEto keylist); + + /** + * @param id ID of the {@link KeyListEto} to be deleted + */ + @DELETE + @Path("/keyitem/{id}/") + void deleteKeyList(@PathParam("id") long id); + + /** + * ATTENTION:
+ * Calling this method may be very expensive. Only use it for {@link KeyList#isCacheable() cachable} {@link KeyList}s. + * Whenever possible prefer using {@link #findKeyItemEtos(KeyItemSearchCriteriaTo)} instead. + * + * @param id the ID of the {@link KeyListEto key-list} {@link KeyItemEto#getKeyListId() owning} the requested + * {@link KeyItemEto items}. + * @return the {@link List} with ALL {@link KeyItemEto}s of the {@link KeyListEto key-list} for the given ID. + */ + @GET + @Path("/keyitem-for-list/{id}/") + List findKeyItemEtosForList(@PathParam("id") long id); + + /** + * @param criteria the {@link KeyItemSearchCriteriaTo} specifying the search query. + * @return the {@link Page} with the matching {@link KeyItemEto}s. + */ + @POST + @Path("/keyitem/search/") + Page findKeyItemEtos(KeyItemSearchCriteriaTo criteria); + + /** + * @param id the ID of the {@link KeyItemEto} + * @return the {@link KeyItemEto} + */ + @GET + @Path("/keyitem/{id}/") + KeyItemEto findKeyItem(@PathParam("id") long id); + + /** + * @param keyitem the {@link KeyItemEto} to be saved + * @return the recently created {@link KeyItemEto} + */ + @POST + @Path("/keyitem/") + KeyItemEto saveKeyItem(KeyItemEto keyitem); + + /** + * @param id ID of the {@link KeyItemEto} to be deleted + */ + @DELETE + @Path("/keyitem/{id}/") + void deleteKeyItem(@PathParam("id") long id); + +} diff --git a/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/AbstractLiteralSearchCriteria.java b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/AbstractLiteralSearchCriteria.java new file mode 100644 index 0000000..494de08 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/AbstractLiteralSearchCriteria.java @@ -0,0 +1,28 @@ +package com.devonfw.module.criteria.common.api.query; + +/** + * Abstract base implementation of {@link LiteralSearchCriteria}. + * + * @param type of property / value to search. + * @since 1.0.0 + */ +public abstract class AbstractLiteralSearchCriteria extends AbstractSearchCriteria + implements LiteralSearchCriteria { + + /** + * The constructor. + * + * @param operator the {@link #getOperator() operator}. + */ + public AbstractLiteralSearchCriteria(SearchOperator operator) { + + super(operator); + } + + @Override + public String toString() { + + return super.toString() + " " + getLiteral(); + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/AbstractSearchCriteria.java b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/AbstractSearchCriteria.java new file mode 100644 index 0000000..fc73d1e --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/AbstractSearchCriteria.java @@ -0,0 +1,39 @@ +package com.devonfw.module.criteria.common.api.query; + +import java.util.Objects; + +/** + * Abstract base implementation of {@link SearchCriteria}. + * + * @param type of property / value to search. + * @since 1.0.0 + */ +public class AbstractSearchCriteria implements SearchCriteria { + + private final SearchOperator operator; + + /** + * The constructor. + * + * @param operator the {@link #getOperator() operator}. + */ + public AbstractSearchCriteria(SearchOperator operator) { + + super(); + Objects.requireNonNull(operator, "operator"); + this.operator = operator; + } + + @Override + public SearchOperator getOperator() { + + return this.operator; + } + + @Override + public String toString() { + + return this.operator.toString(); + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/BooleanSearchCriteria.java b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/BooleanSearchCriteria.java new file mode 100644 index 0000000..98a8b92 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/BooleanSearchCriteria.java @@ -0,0 +1,48 @@ +package com.devonfw.module.criteria.common.api.query; + +/** + * {@link SearchCriteria} for {@link Boolean}. + * + * @since 1.0.0 + */ +public class BooleanSearchCriteria extends AbstractLiteralSearchCriteria { + + private final Boolean literal; + + /** + * The constructor. + * + * @param operator the {@link #getOperator() operator}. + * @param literal the {@link #getLiteral() literal}. + */ + public BooleanSearchCriteria(SearchOperator operator, Boolean literal) { + + super(operator); + this.literal = literal; + } + + @Override + public Boolean getLiteral() { + + return this.literal; + } + + /** + * @param value the literal value to compare with. + * @return {@link BooleanSearchCriteria} using {@link SearchOperator#EQ}. + */ + public static BooleanSearchCriteria eq(Boolean value) { + + return new BooleanSearchCriteria(SearchOperator.EQ, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link BooleanSearchCriteria} using {@link SearchOperator#NEQ}. + */ + public static BooleanSearchCriteria neq(Boolean value) { + + return new BooleanSearchCriteria(SearchOperator.NEQ, value); + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/ComparableSearchOperator.java b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/ComparableSearchOperator.java new file mode 100644 index 0000000..ae11b48 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/ComparableSearchOperator.java @@ -0,0 +1,44 @@ +package com.devonfw.module.criteria.common.api.query; + +/** + * {@link SearchOperator} for {@link Comparable}. + * + * @param type of property / value to search. + * @since 1.0.0 + */ +@SuppressWarnings("rawtypes") +public class ComparableSearchOperator extends SearchOperator { + + /** + * {@link SearchOperator} matching if search hit is less than search value . + */ + public static final ComparableSearchOperator LT = new ComparableSearchOperator<>("<"); + + /** + * Matches if search value is less or equal to search hit(s) in {@link String#compareTo(String) lexicographical + * order}. + */ + public static final ComparableSearchOperator LE = new ComparableSearchOperator<>("<="); + + /** + * Matches if search value is greater than search hit(s) in {@link String#compareTo(String) lexicographical order}. + */ + public static final ComparableSearchOperator GT = new ComparableSearchOperator<>(">"); + + /** + * Matches if search value is greater or equal to search hit(s) in {@link String#compareTo(String) lexicographical + * order}. + */ + public static final ComparableSearchOperator GE = new ComparableSearchOperator<>(">="); + + ComparableSearchOperator(String operator) { + + super(operator); + } + + ComparableSearchOperator(String operator, boolean inverse) { + + super(operator, inverse); + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/IntegerSearchCriteria.java b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/IntegerSearchCriteria.java new file mode 100644 index 0000000..78af1a8 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/IntegerSearchCriteria.java @@ -0,0 +1,97 @@ +package com.devonfw.module.criteria.common.api.query; + +/** + * {@link SearchCriteria} for {@link Integer}. + * + * @since 1.0.0 + */ +public class IntegerSearchCriteria extends NumberSearchCriteria { + + /** + * The constructor. + * + * @param operator the {@link #getOperator() operator}. + * @param literal the {@link #getLiteral() literal}. + */ + public IntegerSearchCriteria(SearchOperator operator, Integer literal) { + + super(operator, literal); + } + + /** + * The constructor. + * + * @param operator the {@link #getOperator() operator}. + * @param literal1 the first {@link #getLiteral() literal}. + * @param literal2 the {@link #getLiteral2() second literal}. + */ + public IntegerSearchCriteria(SearchOperator operator, Integer literal1, Integer literal2) { + + super(operator, literal1, literal2); + } + + /** + * @param value the literal value to compare with. + * @return {@link IntegerSearchCriteria} using {@link SearchOperator#EQ}. + */ + public static IntegerSearchCriteria eq(Integer value) { + + return new IntegerSearchCriteria(SearchOperator.EQ, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link IntegerSearchCriteria} using {@link SearchOperator#NEQ}. + */ + public static IntegerSearchCriteria neq(Integer value) { + + return new IntegerSearchCriteria(SearchOperator.NEQ, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link IntegerSearchCriteria} using {@link ComparableSearchOperator#GT}. + */ + public static IntegerSearchCriteria gt(int value) { + + return new IntegerSearchCriteria(ComparableSearchOperator.GT, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link IntegerSearchCriteria} using {@link ComparableSearchOperator#GE}. + */ + public static IntegerSearchCriteria ge(int value) { + + return new IntegerSearchCriteria(ComparableSearchOperator.GE, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link IntegerSearchCriteria} using {@link ComparableSearchOperator#LT}. + */ + public static IntegerSearchCriteria lt(int value) { + + return new IntegerSearchCriteria(ComparableSearchOperator.LT, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link IntegerSearchCriteria} using {@link ComparableSearchOperator#LE}. + */ + public static IntegerSearchCriteria le(int value) { + + return new IntegerSearchCriteria(ComparableSearchOperator.LE, value); + } + + /** + * @param min the minimum value. + * @param max the maximum value. + * @return {@link IntegerSearchCriteria} using {@link NumberSearchOperator#BETWEEN}. + */ + public static IntegerSearchCriteria between(int min, int max) { + + return new IntegerSearchCriteria(NumberSearchOperator.BETWEEN, min, max); + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/LiteralSearchCriteria.java b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/LiteralSearchCriteria.java new file mode 100644 index 0000000..a2aa3c6 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/LiteralSearchCriteria.java @@ -0,0 +1,16 @@ +package com.devonfw.module.criteria.common.api.query; + +/** + * Interface for {@link SearchCriteria} comparing with a {@link #getLiteral() literal value}. + * + * @param type of property / value to search. + * @since 1.0.0 + */ +public interface LiteralSearchCriteria extends SearchCriteria { + + /** + * @return the literal value to {@link #getOperator() compare with}. + */ + T getLiteral(); + +} diff --git a/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/LongSearchCriteria.java b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/LongSearchCriteria.java new file mode 100644 index 0000000..3f9898c --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/LongSearchCriteria.java @@ -0,0 +1,97 @@ +package com.devonfw.module.criteria.common.api.query; + +/** + * {@link SearchCriteria} for {@link Long}. + * + * @since 1.0.0 + */ +public class LongSearchCriteria extends NumberSearchCriteria { + + /** + * The constructor. + * + * @param operator the {@link #getOperator() operator}. + * @param literal the {@link #getLiteral() literal}. + */ + public LongSearchCriteria(SearchOperator operator, Long literal) { + + super(operator, literal); + } + + /** + * The constructor. + * + * @param operator the {@link #getOperator() operator}. + * @param literal1 the first {@link #getLiteral() literal}. + * @param literal2 the {@link #getLiteral2() second literal}. + */ + public LongSearchCriteria(SearchOperator operator, Long literal1, Long literal2) { + + super(operator, literal1, literal2); + } + + /** + * @param value the literal value to compare with. + * @return {@link LongSearchCriteria} using {@link SearchOperator#EQ}. + */ + public static LongSearchCriteria eq(Long value) { + + return new LongSearchCriteria(SearchOperator.EQ, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link LongSearchCriteria} using {@link SearchOperator#NEQ}. + */ + public static LongSearchCriteria neq(Long value) { + + return new LongSearchCriteria(SearchOperator.NEQ, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link LongSearchCriteria} using {@link ComparableSearchOperator#GT}. + */ + public static LongSearchCriteria gt(long value) { + + return new LongSearchCriteria(ComparableSearchOperator.GT, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link LongSearchCriteria} using {@link ComparableSearchOperator#GE}. + */ + public static LongSearchCriteria ge(long value) { + + return new LongSearchCriteria(ComparableSearchOperator.GE, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link LongSearchCriteria} using {@link ComparableSearchOperator#LT}. + */ + public static LongSearchCriteria lt(long value) { + + return new LongSearchCriteria(ComparableSearchOperator.LT, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link LongSearchCriteria} using {@link ComparableSearchOperator#LE}. + */ + public static LongSearchCriteria le(long value) { + + return new LongSearchCriteria(ComparableSearchOperator.LE, value); + } + + /** + * @param min the minimum value. + * @param max the maximum value. + * @return {@link LongSearchCriteria} using {@link NumberSearchOperator#BETWEEN}. + */ + public static LongSearchCriteria between(long min, long max) { + + return new LongSearchCriteria(NumberSearchOperator.BETWEEN, min, max); + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/NumberSearchCriteria.java b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/NumberSearchCriteria.java new file mode 100644 index 0000000..fab6426 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/NumberSearchCriteria.java @@ -0,0 +1,56 @@ +package com.devonfw.module.criteria.common.api.query; + +/** + * {@link SearchCriteria} for {@link Number}. + * + * @param type of property / value to search. + * @since 1.0.0 + */ +public abstract class NumberSearchCriteria extends AbstractLiteralSearchCriteria { + + private final T literal1; + + private final T literal2; + + /** + * The constructor. + * + * @param operator the {@link #getOperator() operator}. + * @param literal the {@link #getLiteral() literal}. + */ + public NumberSearchCriteria(SearchOperator operator, T literal) { + + super(operator); + this.literal1 = literal; + this.literal2 = null; + } + + /** + * The constructor. + * + * @param operator the {@link #getOperator() operator}. + * @param literal1 the first {@link #getLiteral() literal}. + * @param literal2 the {@link #getLiteral2() second literal}. + */ + public NumberSearchCriteria(SearchOperator operator, T literal1, T literal2) { + + super(operator); + this.literal1 = literal1; + this.literal2 = literal2; + } + + @Override + public T getLiteral() { + + return this.literal1; + } + + /** + * @return the optional second literal (e.g. for BETWEEN min AND max). + */ + public T getLiteral2() { + + return this.literal2; + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/NumberSearchOperator.java b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/NumberSearchOperator.java new file mode 100644 index 0000000..12819d9 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/NumberSearchOperator.java @@ -0,0 +1,26 @@ +package com.devonfw.module.criteria.common.api.query; + +/** + * {@link SearchOperator} for {@link Number}. + * + * @param type of property / value to search. + * @since 1.0.0 + */ +public class NumberSearchOperator extends SearchOperator { + + /** + * {@link SearchOperator} matching if search hit is less than search value . + */ + public static final NumberSearchOperator BETWEEN = new NumberSearchOperator<>("BETWEEN"); + + NumberSearchOperator(String operator) { + + super(operator); + } + + NumberSearchOperator(String operator, boolean inverse) { + + super(operator, inverse); + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/SearchCriteria.java b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/SearchCriteria.java new file mode 100644 index 0000000..1144f06 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/SearchCriteria.java @@ -0,0 +1,16 @@ +package com.devonfw.module.criteria.common.api.query; + +/** + * Interface for search criteria. + * + * @param type of property / value to search. + * @since 1.0.0 + */ +public interface SearchCriteria { + + /** + * @return the {@link SearchOperator}. May not be {@code null}. + */ + SearchOperator getOperator(); + +} diff --git a/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/SearchOperator.java b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/SearchOperator.java new file mode 100644 index 0000000..d34691d --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/SearchOperator.java @@ -0,0 +1,84 @@ +package com.devonfw.module.criteria.common.api.query; + +import java.util.HashMap; +import java.util.Map; + +/** + * Operator to match values (search property, literal). + * + * @param type of property / value to search. + * @since 1.0.0 + */ +public class SearchOperator { + + private static final Map> SYNTAX2OPERATOR_MAP = new HashMap<>(); + + /** {@link SearchOperator} matching if to objects are {@link #equals(Object) equal}. */ + public static final SearchOperator EQ = new SearchOperator<>("=="); + + /** {@link SearchOperator} matching if to objects are not {@link #equals(Object) equal}. */ + public static final SearchOperator NEQ = new SearchOperator<>("<>"); + + private final String syntax; + + private final boolean inverse; + + static { + Class loadClass = ComparableSearchOperator.class; + if (loadClass != null) { + loadClass = StringSearchOperator.class; + assert (loadClass != null); + } + } + + SearchOperator(String operator) { + + this(operator, false); + } + + SearchOperator(String operator, boolean inverse) { + + super(); + this.syntax = operator; + this.inverse = inverse; + SearchOperator duplicate = SYNTAX2OPERATOR_MAP.put(toString(), this); + assert (duplicate == null); + } + + /** + * @return the syntax of this operator (e.g. in SQL or JPQL). + */ + public String getSyntax() { + + return this.syntax; + } + + /** + * @return {@code true} for inverse usage where literal value is first argument and matching property is second + * argument, {@code false} otherwise (normal match). + */ + public boolean isInverse() { + + return this.inverse; + } + + @Override + public String toString() { + + if (this.inverse) { + return "~" + this.syntax; + } else { + return this.syntax; + } + } + + /** + * @param id the {@link #toString() string representation}. + * @return the {@link SearchOperator} for the given {@code id} or {@code null} if not defined. + */ + static SearchOperator get(String id) { + + return SYNTAX2OPERATOR_MAP.get(id); + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/StringSearchCriteria.java b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/StringSearchCriteria.java new file mode 100644 index 0000000..bdae856 --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/StringSearchCriteria.java @@ -0,0 +1,102 @@ +package com.devonfw.module.criteria.common.api.query; + +/** + * {@link SearchCriteria} for {@link String}. + * + * @since 1.0.0 + */ +public class StringSearchCriteria extends AbstractLiteralSearchCriteria { + + private final String literal; + + /** + * The constructor. + * + * @param operator the {@link #getOperator() operator}. + * @param literal the {@link #getLiteral() literal}. + */ + public StringSearchCriteria(SearchOperator operator, String literal) { + + super(operator); + this.literal = literal; + } + + @Override + public String getLiteral() { + + return this.literal; + } + + /** + * @param value the literal value to compare with. + * @return {@link StringSearchCriteria} using {@link SearchOperator#EQ}. + */ + public static StringSearchCriteria eq(String value) { + + return new StringSearchCriteria(SearchOperator.EQ, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link StringSearchCriteria} using {@link SearchOperator#NEQ}. + */ + public static StringSearchCriteria neq(String value) { + + return new StringSearchCriteria(SearchOperator.NEQ, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link StringSearchCriteria} using {@link ComparableSearchOperator#GT}. + */ + public static StringSearchCriteria gt(String value) { + + return new StringSearchCriteria(ComparableSearchOperator.GT, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link StringSearchCriteria} using {@link ComparableSearchOperator#GE}. + */ + public static StringSearchCriteria ge(String value) { + + return new StringSearchCriteria(ComparableSearchOperator.GE, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link StringSearchCriteria} using {@link ComparableSearchOperator#LT}. + */ + public static StringSearchCriteria lt(String value) { + + return new StringSearchCriteria(ComparableSearchOperator.LT, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link StringSearchCriteria} using {@link ComparableSearchOperator#LE}. + */ + public static StringSearchCriteria le(String value) { + + return new StringSearchCriteria(ComparableSearchOperator.LE, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link StringSearchCriteria} using {@link StringSearchOperator#LIKE}. + */ + public static StringSearchCriteria like(String value) { + + return new StringSearchCriteria(StringSearchOperator.LIKE, value); + } + + /** + * @param value the literal value to compare with. + * @return {@link StringSearchCriteria} using {@link StringSearchOperator#NOT_LIKE}. + */ + public static StringSearchCriteria notLike(String value) { + + return new StringSearchCriteria(StringSearchOperator.NOT_LIKE, value); + } + +} diff --git a/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/StringSearchOperator.java b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/StringSearchOperator.java new file mode 100644 index 0000000..f8b715a --- /dev/null +++ b/keywi/api/src/main/java/com/devonfw/module/criteria/common/api/query/StringSearchOperator.java @@ -0,0 +1,32 @@ +package com.devonfw.module.criteria.common.api.query; + +/** + * {@link SearchOperator} for {@link String}. + * + * @since 1.0.0 + */ +public class StringSearchOperator extends ComparableSearchOperator { + + /** {@link SearchOperator} matching if property matches pattern. */ + public static final StringSearchOperator LIKE = new StringSearchOperator("LIKE"); + + /** {@link SearchOperator} matching if property does not match pattern. */ + public static final StringSearchOperator NOT_LIKE = new StringSearchOperator("NOT LIKE"); + + /** {@link SearchOperator} matching if literal value match property pattern. */ + public static final StringSearchOperator INVERSE_LIKE = new StringSearchOperator("LIKE", true); + + /** {@link SearchOperator} matching if literal value does not match property pattern. */ + public static final StringSearchOperator NOT_INVERSE_LIKE = new StringSearchOperator("NOT LIKE", true); + + StringSearchOperator(String operator) { + + super(operator); + } + + StringSearchOperator(String operator, boolean inverse) { + + super(operator, inverse); + } + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/general/common/api/ApplicationEntity.java b/keywi/core/src/main/java/com/devonfw/keywi/general/common/api/ApplicationEntity.java new file mode 100644 index 0000000..03a2307 --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/general/common/api/ApplicationEntity.java @@ -0,0 +1,11 @@ +package com.devonfw.keywi.general.common.api; + +import com.devonfw.module.basic.common.api.entity.GenericEntity; + +/** + * This is the abstract interface for a {@link GenericEntity}. We are using {@link Long} for all {@link #getId() primary + * keys}. + */ +public abstract interface ApplicationEntity extends GenericEntity { + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/general/common/api/security/ApplicationAccessControlConfig.java b/keywi/core/src/main/java/com/devonfw/keywi/general/common/api/security/ApplicationAccessControlConfig.java index d437ebc..a51a5b1 100644 --- a/keywi/core/src/main/java/com/devonfw/keywi/general/common/api/security/ApplicationAccessControlConfig.java +++ b/keywi/core/src/main/java/com/devonfw/keywi/general/common/api/security/ApplicationAccessControlConfig.java @@ -15,11 +15,27 @@ public class ApplicationAccessControlConfig extends AccessControlConfig { private static final String PREFIX = APP_ID + "."; - public static final String PERMISSION_FIND_BINARY_OBJECT = PREFIX + "FindBinaryObject"; + /** @see com.devonfw.keywi.keymanagement.logic.api.usecase.UcFindKeyItem */ + public static final String PERMISSION_FIND_KEY_ITEM = PREFIX + "FindKeyItem"; - public static final String PERMISSION_SAVE_BINARY_OBJECT = PREFIX + "SaveBinaryObject"; + /** + * @see com.devonfw.keywi.keymanagement.logic.api.usecase.UcManageKeyItem#saveKeyItem(com.devonfw.keywi.keymanagement.logic.api.to.KeyItemEto) + */ + public static final String PERMISSION_SAVE_KEY_ITEM = PREFIX + "SaveKeyItem"; + + /** @see com.devonfw.keywi.keymanagement.logic.api.usecase.UcManageKeyItem#deleteKeyItem(long) */ + public static final String PERMISSION_DELETE_KEY_ITEM = PREFIX + "DeleteKeyItem"; + + /** @see com.devonfw.keywi.keymanagement.logic.api.usecase.UcFindKeyList */ + public static final String PERMISSION_FIND_KEY_LIST = PREFIX + "FindKeyList"; + + /** + * @see com.devonfw.keywi.keymanagement.logic.api.usecase.UcManageKeyList#saveKeyList(com.devonfw.keywi.keymanagement.logic.api.to.KeyListEto) + */ + public static final String PERMISSION_SAVE_KEY_LIST = PREFIX + "SaveKeyList"; - public static final String PERMISSION_DELETE_BINARY_OBJECT = PREFIX + "DeleteBinaryObject"; + /** @see com.devonfw.keywi.keymanagement.logic.api.usecase.UcManageKeyList#deleteKeyList(long) */ + public static final String PERMISSION_DELETE_KEY_LIST = PREFIX + "DeleteKeyList"; public static final String GROUP_READ_MASTER_DATA = PREFIX + "ReadMasterData"; @@ -31,8 +47,10 @@ public class ApplicationAccessControlConfig extends AccessControlConfig { public ApplicationAccessControlConfig() { super(); - AccessControlGroup readMasterData = group(GROUP_READ_MASTER_DATA, PERMISSION_FIND_BINARY_OBJECT); - group(GROUP_ADMIN, readMasterData, PERMISSION_SAVE_BINARY_OBJECT, PERMISSION_DELETE_BINARY_OBJECT); + AccessControlGroup readMasterData = + group(GROUP_READ_MASTER_DATA, PERMISSION_FIND_KEY_LIST, PERMISSION_FIND_KEY_ITEM); + group(GROUP_ADMIN, readMasterData, PERMISSION_SAVE_KEY_ITEM, PERMISSION_SAVE_KEY_LIST, PERMISSION_DELETE_KEY_ITEM, + PERMISSION_DELETE_KEY_LIST); } } \ No newline at end of file diff --git a/keywi/core/src/main/java/com/devonfw/keywi/general/logic/api/Keymanagement.java b/keywi/core/src/main/java/com/devonfw/keywi/general/logic/api/Keymanagement.java new file mode 100644 index 0000000..a4e8e1c --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/general/logic/api/Keymanagement.java @@ -0,0 +1,13 @@ +package com.devonfw.keywi.general.logic.api; + +import com.devonfw.keywi.keymanagement.logic.api.usecase.UcFindKeyItem; +import com.devonfw.keywi.keymanagement.logic.api.usecase.UcFindKeyList; +import com.devonfw.keywi.keymanagement.logic.api.usecase.UcManageKeyItem; +import com.devonfw.keywi.keymanagement.logic.api.usecase.UcManageKeyList; + +/** + * Interface for Keymanagement component. + */ +public interface Keymanagement extends UcFindKeyItem, UcManageKeyItem, UcFindKeyList, UcManageKeyList { + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/general/logic/base/AbstractLogic.java b/keywi/core/src/main/java/com/devonfw/keywi/general/logic/base/AbstractLogic.java index feefbf0..ef1c11f 100644 --- a/keywi/core/src/main/java/com/devonfw/keywi/general/logic/base/AbstractLogic.java +++ b/keywi/core/src/main/java/com/devonfw/keywi/general/logic/base/AbstractLogic.java @@ -1,15 +1,19 @@ package com.devonfw.keywi.general.logic.base; -import com.devonfw.keywi.general.common.base.AbstractBeanMapperSupport; - -import com.devonfw.module.basic.common.api.entity.GenericEntity; - +import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; + +import com.devonfw.keywi.general.common.base.AbstractBeanMapperSupport; +import com.devonfw.module.basic.common.api.entity.GenericEntity; +import com.devonfw.module.basic.common.api.entity.PersistenceEntity; + /** * Abstract base class for implementations of business logic in this application. Actual implementations need * to be annotated with {@link javax.inject.Named}. @@ -29,8 +33,8 @@ public AbstractLogic() { /** * Creates a {@link Map} with all {@link GenericEntity entities} from the given {@link Collection} using their - * {@link GenericEntity#getId() ID} as key. All {@link GenericEntity entities} without an - * {@link GenericEntity#getId() ID} ({@code null}) will be ignored. + * {@link GenericEntity#getId() ID} as key. All {@link GenericEntity entities} without an {@link GenericEntity#getId() + * ID} ({@code null}) will be ignored. * * @param is the generic type of the {@link GenericEntity#getId() ID}. * @param is the generic type of the {@link GenericEntity entity}. @@ -78,4 +82,20 @@ protected static > List getEntities2Delete(Co return result; } + /** + * Maps a {@link Page paginated list} of persistent entities to a {@link Page paginated list} of transfer objects. + * + * @param is the generic type of the {@link com.devonfw.module.basic.common.api.to.AbstractEto transfer object}. + * @param is the generic type of the {@link PersistenceEntity entity}. + * @param page is the paginated list to map from. + * @param clazz is the target class to map the paginated entities to. + * @return a {@link Page paginated list of entity transfer objects}. + */ + protected > Page mapPaginatedEntityList(Page page, + Class clazz) { + + List etoList = getBeanMapper().mapList(page.getContent(), clazz); + return new PageImpl<>(etoList, page.getPageable(), page.getTotalElements()); + } + } diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/KeyItemEntity.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/KeyItemEntity.java new file mode 100644 index 0000000..177d403 --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/KeyItemEntity.java @@ -0,0 +1,72 @@ +package com.devonfw.keywi.keymanagement.dataaccess.api; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.MappedSuperclass; +import javax.persistence.Table; +import javax.persistence.Transient; + +import com.devonfw.keywi.keymanagement.common.api.KeyItem; +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.module.basic.common.api.reference.IdRef; +import com.devonfw.module.jpa.dataaccess.api.JpaHelper; + +/** + * {@link MappedSuperclass} as base class for {@link KeyListEntity} and {@link KeyItemEntity}. + */ +@Entity +@Table(name = "KeyItem") +public class KeyItemEntity extends KeyObjectEntity implements KeyItem { + + private static final long serialVersionUID = 1L; + + private String value; + + private KeyListEntity keyList; + + @Override + public String getValue() { + + return this.value; + } + + @Override + public void setValue(String value) { + + this.value = value; + } + + /** + * @return the {@link KeyListEntity} owning this item. + */ + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "keyList") + public KeyListEntity getKeyList() { + + return this.keyList; + } + + /** + * @param keyList new value of {@link #getKeyList()}. + */ + public void setKeyList(KeyListEntity keyList) { + + this.keyList = keyList; + } + + @Override + @Transient + public IdRef getKeyListId() { + + return IdRef.of(this.keyList); + } + + @Override + public void setKeyListId(IdRef keyListId) { + + this.keyList = JpaHelper.asEntity(keyListId, KeyListEntity.class); + } + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/KeyListEntity.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/KeyListEntity.java new file mode 100644 index 0000000..59f83ee --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/KeyListEntity.java @@ -0,0 +1,103 @@ +package com.devonfw.keywi.keymanagement.dataaccess.api; + +import java.util.regex.Pattern; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.keywi.keymanagement.dataaccess.api.datatype.KeyItemProperty; + +/** + * {@link com.devonfw.keywi.general.dataaccess.api.ApplicationPersistenceEntity} for {@link KeyList}. + * + * @since 1.0.0 + */ +@Entity +@Table(name = "KeyList") +public class KeyListEntity extends KeyObjectEntity implements KeyList { + + private static final long serialVersionUID = 1L; + + private KeyItemProperty ordering; + + private boolean valueRequired; + + private Pattern valuePattern; + + private String permission; + + private boolean cacheable; + + /** + * The constructor. + */ + public KeyListEntity() { + + super(); + this.ordering = KeyItemProperty.NAME; + } + + @Column(nullable = false) + @Override + public KeyItemProperty getOrdering() { + + return this.ordering; + } + + @Override + public void setOrdering(KeyItemProperty ordering) { + + this.ordering = ordering; + } + + @Override + public boolean isValueRequired() { + + return this.valueRequired; + } + + @Override + public void setValueRequired(boolean valueRequired) { + + this.valueRequired = valueRequired; + } + + @Override + public Pattern getValuePattern() { + + return this.valuePattern; + } + + @Override + public void setValuePattern(Pattern valuePattern) { + + this.valuePattern = valuePattern; + } + + @Override + public String getPermission() { + + return this.permission; + } + + @Override + public void setPermission(String permission) { + + this.permission = permission; + } + + @Override + public boolean isCacheable() { + + return this.cacheable; + } + + @Override + public void setCacheable(boolean cacheable) { + + this.cacheable = cacheable; + } + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/KeyObjectEntity.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/KeyObjectEntity.java new file mode 100644 index 0000000..0d19a1f --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/KeyObjectEntity.java @@ -0,0 +1,77 @@ +package com.devonfw.keywi.keymanagement.dataaccess.api; + +import javax.persistence.Column; +import javax.persistence.MappedSuperclass; + +import com.devonfw.keywi.general.dataaccess.api.ApplicationPersistenceEntity; +import com.devonfw.keywi.keymanagement.common.api.KeyObject; + +/** + * {@link ApplicationPersistenceEntity} for {@link KeyObject}. + * + * @since 1.0.0 + */ +@MappedSuperclass +public abstract class KeyObjectEntity extends ApplicationPersistenceEntity implements KeyObject { + + private static final long serialVersionUID = 1L; + + private String key; + + private String name; + + private String comment; + + private boolean disabled; + + @Column(name = COLUMN_KEY) + @Override + public String getKey() { + + return this.key; + } + + @Override + public void setKey(String key) { + + this.key = key; + } + + @Column(name = "name") + @Override + public String getName() { + + return this.name; + } + + @Override + public void setName(String name) { + + this.name = name; + } + + @Override + public String getComment() { + + return this.comment; + } + + @Override + public void setComment(String comment) { + + this.comment = comment; + } + + @Override + public boolean isDisabled() { + + return this.disabled; + } + + @Override + public void setDisabled(boolean disabled) { + + this.disabled = disabled; + } + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/repo/KeyItemRepository.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/repo/KeyItemRepository.java new file mode 100644 index 0000000..fd31639 --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/repo/KeyItemRepository.java @@ -0,0 +1,83 @@ +package com.devonfw.keywi.keymanagement.dataaccess.api.repo; + +import static com.querydsl.core.alias.Alias.$; + +import java.util.List; + +import org.springframework.data.domain.Page; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.keywi.keymanagement.dataaccess.api.KeyItemEntity; +import com.devonfw.keywi.keymanagement.dataaccess.api.datatype.KeyItemProperty; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyItemSearchCriteriaTo; +import com.devonfw.module.basic.common.api.reference.IdRef; +import com.devonfw.module.criteria.common.api.query.StringSearchCriteria; +import com.devonfw.module.criteria.dataaccess.base.query.SearchCriteriaMapper; +import com.devonfw.module.jpa.dataaccess.api.QueryUtil; +import com.devonfw.module.jpa.dataaccess.api.data.DefaultRepository; +import com.querydsl.core.types.Expression; +import com.querydsl.core.types.Order; +import com.querydsl.core.types.OrderSpecifier; +import com.querydsl.core.types.dsl.StringPath; +import com.querydsl.jpa.impl.JPAQuery; + +/** + * {@link DefaultRepository} for {@link KeyItemEntity} + */ +public interface KeyItemRepository extends DefaultRepository { + + /** + * @param id + * @return + */ + @Query("SELECT items FROM KeyItemEntity items" // + + " WHERE items.keyList.id = :id") + List findAllForList(@Param("id") Long id); + + /** + * @param criteria the {@link KeyItemSearchCriteriaTo} to search. + * @return the {@link Page} with the matching {@link KeyItemEntity} hits. + */ + default Page find(KeyItemSearchCriteriaTo criteria) { + + KeyItemEntity alias = newDslAlias(); + JPAQuery query = newDslQuery(alias); + + IdRef keyListId = criteria.getKeyListId(); + query.where($(alias.getKeyList().getId()).eq(keyListId.getId())); + + StringSearchCriteria name = criteria.getName(); + if (name != null) { + StringPath namePath = $(alias.getName()); + SearchCriteriaMapper.apply(namePath, name, query); + } + + KeyItemProperty ordering = criteria.getOrdering(); + applyOrdering(alias, query, ordering); + + return QueryUtil.get().findPaginated(criteria.getPageable(), query, false); + } + + default void applyOrdering(KeyItemEntity alias, JPAQuery query, KeyItemProperty ordering) { + + Expression> orderProperty = null; + switch (ordering) { + case NAME: + orderProperty = $(alias.getName()); + break; + case KEY: + orderProperty = $(alias.getKey()); + break; + case VALUE: + orderProperty = $(alias.getValue()); + break; + case COMMENT: + orderProperty = $(alias.getComment()); + break; + } + query.orderBy(new OrderSpecifier<>(Order.ASC, orderProperty)); + } + +} \ No newline at end of file diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/repo/KeyListRepository.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/repo/KeyListRepository.java new file mode 100644 index 0000000..553fae3 --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/dataaccess/api/repo/KeyListRepository.java @@ -0,0 +1,11 @@ +package com.devonfw.keywi.keymanagement.dataaccess.api.repo; + +import com.devonfw.keywi.keymanagement.dataaccess.api.KeyListEntity; +import com.devonfw.module.jpa.dataaccess.api.data.DefaultRepository; + +/** + * {@link DefaultRepository} for {@link KeyListEntity} + */ +public interface KeyListRepository extends DefaultRepository { + +} \ No newline at end of file diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/api/usecase/UcFindKeyItem.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/api/usecase/UcFindKeyItem.java new file mode 100644 index 0000000..8213d1c --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/api/usecase/UcFindKeyItem.java @@ -0,0 +1,43 @@ +package com.devonfw.keywi.keymanagement.logic.api.usecase; + +import java.util.List; + +import org.springframework.data.domain.Page; + +import com.devonfw.keywi.general.logic.base.AbstractUc; +import com.devonfw.keywi.keymanagement.common.api.KeyItem; +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyItemEto; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyItemSearchCriteriaTo; +import com.devonfw.module.basic.common.api.reference.IdRef; + +/** + * {@link AbstractUc Use-case} to search and retrieve {@link KeyItem}s. + * + * @since 1.0.0 + */ +public interface UcFindKeyItem { + + /** + * @param id the {@link IdRef} of the requested {@link KeyItem}. + * @return The {@link KeyItemEto} with id 'id' + */ + KeyItemEto findKeyItem(IdRef id); + + /** + * ATTENTION:
+ * Calling this method may be very expensive. Only use it for {@link KeyList#isCacheable() cachable} {@link KeyList}s. + * Whenever possible prefer using {@link #findKeyItemEtos(KeyItemSearchCriteriaTo)} instead. + * + * @param id the {@link IdRef} of the {@link KeyItem#getKeyListId() owning} {@link KeyList}. + * @return the {@link List} of ALL {@link KeyItemEto}s. + */ + List findKeyItemEtosForList(IdRef id); + + /** + * @param criteria the {@link KeyItemSearchCriteriaTo} specifying the search query. + * @return the {@link Page} with the matching {@link KeyItemEto}s. + */ + Page findKeyItemEtos(KeyItemSearchCriteriaTo criteria); + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/api/usecase/UcFindKeyList.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/api/usecase/UcFindKeyList.java new file mode 100644 index 0000000..cc002bc --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/api/usecase/UcFindKeyList.java @@ -0,0 +1,27 @@ +package com.devonfw.keywi.keymanagement.logic.api.usecase; + +import java.util.List; + +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyListEto; +import com.devonfw.module.basic.common.api.reference.IdRef; + +/** + * {@link com.devonfw.keywi.general.logic.base.AbstractUc Use-case} to search and retrieve {@link KeyList}s. + * + * @since 1.0.0 + */ +public interface UcFindKeyList { + + /** + * @param id the {@link IdRef} of the requested {@link KeyList}. + * @return the {@link KeyListEto} with the given {@code id} or {@code null} if not found. + */ + KeyListEto findKeyList(IdRef id); + + /** + * @return the {@link List} of all {@link KeyListEto}s. + */ + List findKeyListEtos(); + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/api/usecase/UcManageKeyItem.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/api/usecase/UcManageKeyItem.java new file mode 100644 index 0000000..64f6e87 --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/api/usecase/UcManageKeyItem.java @@ -0,0 +1,26 @@ +package com.devonfw.keywi.keymanagement.logic.api.usecase; + +import com.devonfw.keywi.keymanagement.common.api.KeyItem; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyItemEto; +import com.devonfw.module.basic.common.api.reference.IdRef; + +/** + * Interface of UcManageKeyItem to centralize documentation and signatures of methods. + */ +public interface UcManageKeyItem { + + /** + * @param id the {@link IdRef} of the {@link KeyItem} to delete. + * @return boolean {@code true} if the keyItem has been deleted, {@code false} otherwise + */ + boolean deleteKeyItem(IdRef id); + + /** + * Saves a keyItem and store it in the database. + * + * @param keyItem the {@link KeyItemEto} to create. + * @return the new {@link KeyItemEto} that has been saved with ID and version. + */ + KeyItemEto saveKeyItem(KeyItemEto keyItem); + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/api/usecase/UcManageKeyList.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/api/usecase/UcManageKeyList.java new file mode 100644 index 0000000..98368e0 --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/api/usecase/UcManageKeyList.java @@ -0,0 +1,27 @@ +package com.devonfw.keywi.keymanagement.logic.api.usecase; + +import com.devonfw.keywi.keymanagement.common.api.KeyItem; +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyListEto; +import com.devonfw.module.basic.common.api.reference.IdRef; + +/** + * Interface of UcManageKeyList to centralize documentation and signatures of methods. + */ +public interface UcManageKeyList { + + /** + * @param id the {@link IdRef} of the {@link KeyItem} to delete. + * @return boolean {@code true} if the keyList has been deleted, {@code false} otherwise + */ + boolean deleteKeyList(IdRef id); + + /** + * Saves a keyList and store it in the database. + * + * @param keyList the {@link KeyListEto} to create. + * @return the new {@link KeyListEto} that has been saved with ID and version. + */ + KeyListEto saveKeyList(KeyListEto keyList); + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/base/usecase/AbstractKeyItemUc.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/base/usecase/AbstractKeyItemUc.java new file mode 100644 index 0000000..f8a3b42 --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/base/usecase/AbstractKeyItemUc.java @@ -0,0 +1,27 @@ +package com.devonfw.keywi.keymanagement.logic.base.usecase; + +import javax.inject.Inject; + +import com.devonfw.keywi.general.logic.base.AbstractUc; +import com.devonfw.keywi.keymanagement.dataaccess.api.repo.KeyItemRepository; + +/** + * Abstract use case for KeyItems, which provides access to the commonly necessary data access objects. + */ +public class AbstractKeyItemUc extends AbstractUc { + + /** @see #getKeyItemRepository() */ + @Inject + private KeyItemRepository keyItemRepository; + + /** + * Returns the field 'keyItemRepository'. + * + * @return the {@link KeyItemRepository} instance. + */ + public KeyItemRepository getKeyItemRepository() { + + return this.keyItemRepository; + } + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/base/usecase/AbstractKeyListUc.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/base/usecase/AbstractKeyListUc.java new file mode 100644 index 0000000..06f74f0 --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/base/usecase/AbstractKeyListUc.java @@ -0,0 +1,27 @@ +package com.devonfw.keywi.keymanagement.logic.base.usecase; + +import javax.inject.Inject; + +import com.devonfw.keywi.general.logic.base.AbstractUc; +import com.devonfw.keywi.keymanagement.dataaccess.api.repo.KeyListRepository; + +/** + * Abstract use case for KeyLists, which provides access to the commonly necessary data access objects. + */ +public class AbstractKeyListUc extends AbstractUc { + + /** @see #getKeyListRepository() */ + @Inject + private KeyListRepository keyListRepository; + + /** + * Returns the field 'keyListRepository'. + * + * @return the {@link KeyListRepository} instance. + */ + public KeyListRepository getKeyListRepository() { + + return this.keyListRepository; + } + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/KeymanagementImpl.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/KeymanagementImpl.java new file mode 100644 index 0000000..2499407 --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/KeymanagementImpl.java @@ -0,0 +1,95 @@ +package com.devonfw.keywi.keymanagement.logic.impl; + +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.springframework.data.domain.Page; + +import com.devonfw.keywi.general.logic.api.Keymanagement; +import com.devonfw.keywi.general.logic.base.AbstractComponentFacade; +import com.devonfw.keywi.keymanagement.common.api.KeyItem; +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyItemEto; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyItemSearchCriteriaTo; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyListEto; +import com.devonfw.keywi.keymanagement.logic.api.usecase.UcFindKeyItem; +import com.devonfw.keywi.keymanagement.logic.api.usecase.UcFindKeyList; +import com.devonfw.keywi.keymanagement.logic.api.usecase.UcManageKeyItem; +import com.devonfw.keywi.keymanagement.logic.api.usecase.UcManageKeyList; +import com.devonfw.module.basic.common.api.reference.IdRef; + +/** + * Implementation of component interface of keymanagement + */ +@Named +public class KeymanagementImpl extends AbstractComponentFacade implements Keymanagement { + + @Inject + private UcFindKeyItem ucFindKeyItem; + + @Inject + private UcManageKeyItem ucManageKeyItem; + + @Inject + private UcFindKeyList ucFindKeyList; + + @Inject + private UcManageKeyList ucManageKeyList; + + @Override + public List findKeyItemEtosForList(IdRef id) { + + return this.ucFindKeyItem.findKeyItemEtosForList(id); + } + + @Override + public Page findKeyItemEtos(KeyItemSearchCriteriaTo criteria) { + + return this.ucFindKeyItem.findKeyItemEtos(criteria); + } + + @Override + public KeyItemEto findKeyItem(IdRef id) { + + return this.ucFindKeyItem.findKeyItem(id); + } + + @Override + public KeyItemEto saveKeyItem(KeyItemEto keyitem) { + + return this.ucManageKeyItem.saveKeyItem(keyitem); + } + + @Override + public boolean deleteKeyItem(IdRef id) { + + return this.ucManageKeyItem.deleteKeyItem(id); + } + + @Override + public KeyListEto findKeyList(IdRef id) { + + return this.ucFindKeyList.findKeyList(id); + } + + @Override + public List findKeyListEtos() { + + return this.ucFindKeyList.findKeyListEtos(); + } + + @Override + public KeyListEto saveKeyList(KeyListEto keylist) { + + return this.ucManageKeyList.saveKeyList(keylist); + } + + @Override + public boolean deleteKeyList(IdRef id) { + + return this.ucManageKeyList.deleteKeyList(id); + } + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/usecase/UcFindKeyItemImpl.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/usecase/UcFindKeyItemImpl.java new file mode 100644 index 0000000..b4df888 --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/usecase/UcFindKeyItemImpl.java @@ -0,0 +1,68 @@ +package com.devonfw.keywi.keymanagement.logic.impl.usecase; + +import java.util.List; +import java.util.Optional; + +import javax.annotation.security.RolesAllowed; +import javax.inject.Named; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.Page; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import com.devonfw.keywi.general.common.api.security.ApplicationAccessControlConfig; +import com.devonfw.keywi.keymanagement.common.api.KeyItem; +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.keywi.keymanagement.dataaccess.api.KeyItemEntity; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyItemEto; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyItemSearchCriteriaTo; +import com.devonfw.keywi.keymanagement.logic.api.usecase.UcFindKeyItem; +import com.devonfw.keywi.keymanagement.logic.base.usecase.AbstractKeyItemUc; +import com.devonfw.module.basic.common.api.reference.IdRef; + +/** + * Use case implementation for searching, filtering and getting KeyItems + */ +@Named +@Validated +@Transactional +public class UcFindKeyItemImpl extends AbstractKeyItemUc implements UcFindKeyItem { + + /** Logger instance. */ + private static final Logger LOG = LoggerFactory.getLogger(UcFindKeyItemImpl.class); + + @Override + @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_FIND_KEY_ITEM) + public KeyItemEto findKeyItem(IdRef id) { + + LOG.debug("Get KeyItem with id {} from database.", id); + if (id == null) { + return null; + } + Optional foundEntity = getKeyItemRepository().findById(id.getId()); + if (foundEntity.isPresent()) { + return getBeanMapper().map(foundEntity.get(), KeyItemEto.class); + } else { + return null; + } + } + + @Override + @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_FIND_KEY_ITEM) + public List findKeyItemEtosForList(IdRef id) { + + List items = getKeyItemRepository().findAllForList(id.getId()); + return getBeanMapper().mapList(items, KeyItemEto.class); + } + + @Override + @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_FIND_KEY_ITEM) + public Page findKeyItemEtos(KeyItemSearchCriteriaTo criteria) { + + Page items = getKeyItemRepository().find(criteria); + return mapPaginatedEntityList(items, KeyItemEto.class); + } + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/usecase/UcFindKeyListImpl.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/usecase/UcFindKeyListImpl.java new file mode 100644 index 0000000..dafcbd1 --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/usecase/UcFindKeyListImpl.java @@ -0,0 +1,56 @@ +package com.devonfw.keywi.keymanagement.logic.impl.usecase; + +import java.util.List; +import java.util.Optional; + +import javax.annotation.security.RolesAllowed; +import javax.inject.Named; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import com.devonfw.keywi.general.common.api.security.ApplicationAccessControlConfig; +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.keywi.keymanagement.dataaccess.api.KeyListEntity; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyListEto; +import com.devonfw.keywi.keymanagement.logic.api.usecase.UcFindKeyList; +import com.devonfw.keywi.keymanagement.logic.base.usecase.AbstractKeyListUc; +import com.devonfw.module.basic.common.api.reference.IdRef; + +/** + * Use case implementation for searching, filtering and getting KeyLists + */ +@Named +@Validated +@Transactional +public class UcFindKeyListImpl extends AbstractKeyListUc implements UcFindKeyList { + + /** Logger instance. */ + private static final Logger LOG = LoggerFactory.getLogger(UcFindKeyListImpl.class); + + @Override + @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_FIND_KEY_LIST) + public KeyListEto findKeyList(IdRef id) { + + LOG.debug("Get KeyList with id {} from database.", id); + if (id == null) { + return null; + } + Optional foundEntity = getKeyListRepository().findById(id.getId()); + if (foundEntity.isPresent()) + return getBeanMapper().map(foundEntity.get(), KeyListEto.class); + else + return null; + } + + @Override + @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_FIND_KEY_LIST) + public List findKeyListEtos() { + + List keyListEntities = getKeyListRepository().findAll(); + return getBeanMapper().mapList(keyListEntities, KeyListEto.class); + } + +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/usecase/UcManageKeyItemImpl.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/usecase/UcManageKeyItemImpl.java new file mode 100644 index 0000000..cdcc0b1 --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/usecase/UcManageKeyItemImpl.java @@ -0,0 +1,57 @@ +package com.devonfw.keywi.keymanagement.logic.impl.usecase; + +import java.util.Objects; + +import javax.annotation.security.RolesAllowed; +import javax.inject.Named; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import com.devonfw.keywi.general.common.api.security.ApplicationAccessControlConfig; +import com.devonfw.keywi.keymanagement.common.api.KeyItem; +import com.devonfw.keywi.keymanagement.dataaccess.api.KeyItemEntity; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyItemEto; +import com.devonfw.keywi.keymanagement.logic.api.usecase.UcManageKeyItem; +import com.devonfw.keywi.keymanagement.logic.base.usecase.AbstractKeyItemUc; +import com.devonfw.module.basic.common.api.reference.IdRef; + +/** + * Use case implementation for modifying and deleting KeyItems + */ +@Named +@Validated +@Transactional +public class UcManageKeyItemImpl extends AbstractKeyItemUc implements UcManageKeyItem { + + /** Logger instance. */ + private static final Logger LOG = LoggerFactory.getLogger(UcManageKeyItemImpl.class); + + @Override + @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_DELETE_KEY_ITEM) + public boolean deleteKeyItem(IdRef id) { + + if (id == null) { + return false; + } + getKeyItemRepository().deleteById(id.getId()); + LOG.debug("The keyItem with id '{}' has been deleted.", id); + return true; + } + + @Override + @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_SAVE_KEY_ITEM) + public KeyItemEto saveKeyItem(KeyItemEto keyItem) { + + Objects.requireNonNull(keyItem, "keyItem"); + + KeyItemEntity keyItemEntity = getBeanMapper().map(keyItem, KeyItemEntity.class); + + // initialize, validate keyItemEntity here if necessary + KeyItemEntity resultEntity = getKeyItemRepository().save(keyItemEntity); + LOG.debug("KeyItem with id '{}' has been created.", resultEntity.getId()); + return getBeanMapper().map(resultEntity, KeyItemEto.class); + } +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/usecase/UcManageKeyListImpl.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/usecase/UcManageKeyListImpl.java new file mode 100644 index 0000000..3d2a36e --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/logic/impl/usecase/UcManageKeyListImpl.java @@ -0,0 +1,57 @@ +package com.devonfw.keywi.keymanagement.logic.impl.usecase; + +import java.util.Objects; + +import javax.annotation.security.RolesAllowed; +import javax.inject.Named; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import com.devonfw.keywi.general.common.api.security.ApplicationAccessControlConfig; +import com.devonfw.keywi.keymanagement.common.api.KeyList; +import com.devonfw.keywi.keymanagement.dataaccess.api.KeyListEntity; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyListEto; +import com.devonfw.keywi.keymanagement.logic.api.usecase.UcManageKeyList; +import com.devonfw.keywi.keymanagement.logic.base.usecase.AbstractKeyListUc; +import com.devonfw.module.basic.common.api.reference.IdRef; + +/** + * Use case implementation for modifying and deleting KeyLists + */ +@Named +@Validated +@Transactional +public class UcManageKeyListImpl extends AbstractKeyListUc implements UcManageKeyList { + + /** Logger instance. */ + private static final Logger LOG = LoggerFactory.getLogger(UcManageKeyListImpl.class); + + @Override + @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_DELETE_KEY_LIST) + public boolean deleteKeyList(IdRef id) { + + if (id == null) { + return false; + } + getKeyListRepository().deleteById(id.getId()); + LOG.debug("The keyList with id '{}' has been deleted.", id); + return true; + } + + @Override + @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_SAVE_KEY_LIST) + public KeyListEto saveKeyList(KeyListEto keyList) { + + Objects.requireNonNull(keyList, "keyList"); + + KeyListEntity keyListEntity = getBeanMapper().map(keyList, KeyListEntity.class); + + // initialize, validate keyListEntity here if necessary + KeyListEntity resultEntity = getKeyListRepository().save(keyListEntity); + LOG.debug("KeyList with id '{}' has been created.", resultEntity.getId()); + return getBeanMapper().map(resultEntity, KeyListEto.class); + } +} diff --git a/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/service/impl/rest/KeymanagementRestServiceImpl.java b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/service/impl/rest/KeymanagementRestServiceImpl.java new file mode 100644 index 0000000..8ae02c7 --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/keywi/keymanagement/service/impl/rest/KeymanagementRestServiceImpl.java @@ -0,0 +1,80 @@ +package com.devonfw.keywi.keymanagement.service.impl.rest; + +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.springframework.data.domain.Page; + +import com.devonfw.keywi.general.logic.api.Keymanagement; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyItemEto; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyItemSearchCriteriaTo; +import com.devonfw.keywi.keymanagement.logic.api.to.KeyListEto; +import com.devonfw.keywi.keymanagement.service.api.rest.KeymanagementRestService; +import com.devonfw.module.basic.common.api.reference.IdRef; + +/** + * The service implementation for REST calls in order to execute the logic of component {@link Keymanagement}. + */ +@Named("KeymanagementRestService") +public class KeymanagementRestServiceImpl implements KeymanagementRestService { + + @Inject + private Keymanagement keymanagement; + + @Override + public KeyItemEto findKeyItem(long id) { + + return this.keymanagement.findKeyItem(IdRef.of(id)); + } + + @Override + public List findKeyListEtos() { + + return this.keymanagement.findKeyListEtos(); + } + + @Override + public List findKeyItemEtosForList(long id) { + + return this.keymanagement.findKeyItemEtosForList(IdRef.of(id)); + } + + @Override + public Page findKeyItemEtos(KeyItemSearchCriteriaTo criteria) { + + return this.keymanagement.findKeyItemEtos(criteria); + } + + @Override + public KeyItemEto saveKeyItem(KeyItemEto keyitem) { + + return this.keymanagement.saveKeyItem(keyitem); + } + + @Override + public void deleteKeyItem(long id) { + + this.keymanagement.deleteKeyItem(IdRef.of(id)); + } + + @Override + public KeyListEto findKeyList(long id) { + + return this.keymanagement.findKeyList(IdRef.of(id)); + } + + @Override + public KeyListEto saveKeyList(KeyListEto keylist) { + + return this.keymanagement.saveKeyList(keylist); + } + + @Override + public void deleteKeyList(long id) { + + this.keymanagement.deleteKeyList(IdRef.of(id)); + } + +} diff --git a/keywi/core/src/main/java/com/devonfw/module/criteria/dataaccess/base/query/SearchCriteriaMapper.java b/keywi/core/src/main/java/com/devonfw/module/criteria/dataaccess/base/query/SearchCriteriaMapper.java new file mode 100644 index 0000000..d39b61e --- /dev/null +++ b/keywi/core/src/main/java/com/devonfw/module/criteria/dataaccess/base/query/SearchCriteriaMapper.java @@ -0,0 +1,79 @@ +package com.devonfw.module.criteria.dataaccess.base.query; + +import java.util.HashMap; +import java.util.Map; + +import com.devonfw.module.criteria.common.api.query.ComparableSearchOperator; +import com.devonfw.module.criteria.common.api.query.LiteralSearchCriteria; +import com.devonfw.module.criteria.common.api.query.NumberSearchCriteria; +import com.devonfw.module.criteria.common.api.query.NumberSearchOperator; +import com.devonfw.module.criteria.common.api.query.SearchOperator; +import com.devonfw.module.criteria.common.api.query.StringSearchOperator; +import com.querydsl.core.types.Constant; +import com.querydsl.core.types.ConstantImpl; +import com.querydsl.core.types.Expression; +import com.querydsl.core.types.Operator; +import com.querydsl.core.types.Ops; +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.jpa.impl.JPAQuery; + +/** + * TODO hohwille This type ... + * + * @since 1.0.0 + */ +public class SearchCriteriaMapper { + + private static final Map OPERATOR_MAP = createOperatorMap(); + + /** + * @return + */ + private static Map createOperatorMap() { + + Map map = new HashMap<>(); + map.put(SearchOperator.EQ.getSyntax(), Ops.EQ); + map.put(SearchOperator.NEQ.getSyntax(), Ops.NE); + map.put(ComparableSearchOperator.GE.getSyntax(), Ops.GOE); + map.put(ComparableSearchOperator.GT.getSyntax(), Ops.GT); + map.put(ComparableSearchOperator.LE.getSyntax(), Ops.LOE); + map.put(ComparableSearchOperator.LT.getSyntax(), Ops.LT); + map.put(StringSearchOperator.LIKE.getSyntax(), Ops.LIKE); + map.put(NumberSearchOperator.BETWEEN.getSyntax(), Ops.BETWEEN); + return map; + } + + public static Predicate map(Expression expression, LiteralSearchCriteria criteria) { + + SearchOperator searchOperator = criteria.getOperator(); + Operator operator = map(searchOperator); + Constant literal = ConstantImpl.create(criteria.getLiteral()); + if (operator == Ops.BETWEEN) { + Number max = ((NumberSearchCriteria) criteria).getLiteral2(); + Constant literal2 = ConstantImpl.create(max); + return Expressions.booleanOperation(operator, expression, literal, literal2); + } else { + if (searchOperator.isInverse()) { + return Expressions.booleanOperation(operator, literal, expression); + } else { + return Expressions.booleanOperation(operator, expression, literal); + } + } + } + + /** + * @param operator + * @return + */ + public static Operator map(SearchOperator operator) { + + return OPERATOR_MAP.get(operator.getSyntax()); + } + + public static void apply(Expression expression, LiteralSearchCriteria criteria, JPAQuery query) { + + query.where(map(expression, criteria)); + } + +}