Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ ApplicationResolver applicationResolver() {
.type(Type.DATE)
.build()
)
.attribute(SimpleAttribute.builder()
.name(AttributeName.of("is_adult"))
.column(ColumnName.of("is_adult"))
.type(Type.BOOLEAN)
.defaultValue("true")
.build())
.attribute(SimpleAttribute.builder()
.name(AttributeName.of("shoe_size"))
.column(ColumnName.of("shoe_size"))
.type(Type.LONG)
.defaultValue("40")
.build())
.searchFilter(AttributeSearchFilter.builder()
.operation(Operation.EXACT)
.name(FilterName.of("first_name"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.contentgrid.appserver.application.model.values.ColumnName;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -56,6 +57,10 @@ default boolean hasFlag(Class<? extends AttributeFlag> flagClass) {
return getFlags().stream().anyMatch(flagClass::isInstance);
}

default <T extends AttributeFlag> Optional<T> findFlag(Class<T> flagClass) {
return getFlags().stream().filter(flagClass::isInstance).findFirst().map(flagClass::cast);
}

/**
* Returns whether this attribute is ignored in request and response bodies.
* @return whether this attribute is ignored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@
import com.contentgrid.appserver.application.model.i18n.TranslationBuilderSupport;
import com.contentgrid.appserver.application.model.values.AttributeName;
import com.contentgrid.appserver.application.model.values.ColumnName;
import com.contentgrid.appserver.application.model.values.DataEntry.BooleanDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.DecimalDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.InstantDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.LocalDateDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.LongDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.NullDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.ScalarDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.StringDataEntry;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDate;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -61,6 +73,8 @@ public class SimpleAttribute implements Attribute {
*/
List<Constraint> constraints;

ScalarDataEntry defaultValue;

/**
* Defines the data types supported for attributes.
*/
Expand All @@ -71,12 +85,13 @@ public enum Type {
TEXT,
DATE,
DATETIME,
UUID;
UUID,
;
}

@Builder
SimpleAttribute(@NonNull AttributeName name, ConfigurableTranslatable<AttributeTranslations, ConfigurableAttributeTranslations> translations, @NonNull ColumnName column,
@NonNull Type type, @Singular Set<AttributeFlag> flags, @Singular List<Constraint> constraints) {
@NonNull Type type, @Singular Set<AttributeFlag> flags, @Singular List<Constraint> constraints, String defaultValue) {
this.name = name;
this.translations = translations.withTranslationsBy(Locale.ROOT, t -> {
if(t.getName() == null) {
Expand All @@ -91,6 +106,22 @@ public enum Type {
for (var flag : this.flags) {
flag.checkSupported(this);
}
this.defaultValue = convertDefaultValueType(type, defaultValue);
}

private static ScalarDataEntry convertDefaultValueType(Type type, String defaultValue) {
if (defaultValue == null) {
return NullDataEntry.INSTANCE;
}
return switch(type) {
case LONG -> new LongDataEntry(Long.valueOf(defaultValue));
case DOUBLE -> new DecimalDataEntry(new BigDecimal(defaultValue));
case BOOLEAN -> new BooleanDataEntry(Boolean.parseBoolean(defaultValue));
case TEXT -> new StringDataEntry(defaultValue);
case DATE -> new LocalDateDataEntry(LocalDate.parse(defaultValue));
case DATETIME -> new InstantDataEntry(Instant.parse(defaultValue));
case UUID -> new StringDataEntry(UUID.fromString(defaultValue).toString());
};
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.contentgrid.appserver.application.model.attributes.flags;

import com.contentgrid.appserver.application.model.attributes.Attribute;
import com.contentgrid.appserver.application.model.attributes.SimpleAttribute;
import com.contentgrid.appserver.application.model.exceptions.InvalidFlagException;
import com.contentgrid.appserver.application.model.values.DataEntry.BooleanDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.DecimalDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.InstantDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.LocalDateDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.LongDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.ScalarDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.StringDataEntry;
import lombok.NonNull;
import lombok.Value;

@Value(staticConstructor = "of")
public class DefaultValueFlag implements AttributeFlag {
@Override
public void checkSupported(Attribute attribute) {
if (attribute instanceof SimpleAttribute simp) {

// TODO
var neededDataEntry = switch(simp.getType()) {
case LONG -> LongDataEntry.class;
case DOUBLE -> DecimalDataEntry.class;
case BOOLEAN -> BooleanDataEntry.class;
case TEXT, UUID -> StringDataEntry.class;
case DATE -> LocalDateDataEntry.class;
case DATETIME -> InstantDataEntry.class;
};

if (!neededDataEntry.isAssignableFrom(defaultValue.getClass())) {
throw new InvalidFlagException("Invalid type");
}
} else {
throw new InvalidFlagException("No composites for default values");
}

}

@NonNull
ScalarDataEntry defaultValue;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.contentgrid.appserver.domain.data;
package com.contentgrid.appserver.application.model.values;

import com.contentgrid.appserver.application.model.values.EntityName;
import com.contentgrid.appserver.domain.data.DataEntry.AnyRelationDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.FileDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.PlainDataEntry;
import com.contentgrid.appserver.domain.values.EntityId;
import com.contentgrid.appserver.application.model.values.DataEntry.AnyRelationDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.FileDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.PlainDataEntry;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.contentgrid.appserver.domain.values;
package com.contentgrid.appserver.application.model.values;

import java.io.Serializable;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public class ModelTestFixtures {
.constraint(Constraint.allowedValues(List.of("female", "male")))
.build();

public static final SimpleAttribute PERSON_IS_ADULT = SimpleAttribute.builder()
.name(AttributeName.of("is_adult"))
.column(ColumnName.of("is_adult"))
.type(Type.BOOLEAN)
.defaultValue("true")
.build();

public static final Entity PERSON = Entity.builder()
.name(EntityName.of("person"))
.table(TableName.of("person"))
Expand All @@ -99,6 +106,7 @@ public class ModelTestFixtures {
.attribute(PERSON_VAT)
.attribute(PERSON_AGE)
.attribute(PERSON_GENDER)
.attribute(PERSON_IS_ADULT)
.searchFilter(AttributeSearchFilter.builder()
.operation(Operation.PREFIX)
.attribute(PERSON_NAME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.contentgrid.appserver.domain.values;

import com.contentgrid.appserver.application.model.values.EntityId;
import com.contentgrid.appserver.application.model.values.EntityName;
import com.contentgrid.appserver.domain.values.version.UnspecifiedVersion;
import com.contentgrid.appserver.domain.values.version.Version;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.contentgrid.appserver.domain.values;

import com.contentgrid.appserver.application.model.values.EntityId;
import com.contentgrid.appserver.application.model.values.EntityName;
import com.contentgrid.appserver.domain.values.version.Version;
import com.contentgrid.appserver.domain.values.version.VersionConstraint;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.contentgrid.appserver.domain.values;

import com.contentgrid.appserver.application.model.values.EntityId;
import com.contentgrid.appserver.application.model.values.EntityName;
import com.contentgrid.appserver.application.model.values.RelationName;
import com.contentgrid.appserver.domain.values.version.UnspecifiedVersion;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.contentgrid.appserver.domain.values;

import com.contentgrid.appserver.application.model.values.EntityId;
import com.contentgrid.appserver.application.model.values.EntityName;
import com.contentgrid.appserver.application.model.values.RelationName;
import com.contentgrid.appserver.domain.values.version.Version;
import com.contentgrid.appserver.domain.values.version.VersionConstraint;
import lombok.AccessLevel;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import com.contentgrid.appserver.application.model.values.AttributeName;
import com.contentgrid.appserver.application.model.values.EntityName;
import com.contentgrid.appserver.domain.authorization.AuthorizationContext;
import com.contentgrid.appserver.domain.data.DataEntry.FileDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.FileDataEntry;
import com.contentgrid.appserver.domain.data.InvalidPropertyDataException;
import com.contentgrid.appserver.domain.values.EntityId;
import com.contentgrid.appserver.application.model.values.EntityId;
import com.contentgrid.appserver.domain.values.version.Version;
import com.contentgrid.appserver.domain.values.version.VersionConstraint;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
import com.contentgrid.appserver.contentstore.api.range.ContentRangeRequest;
import com.contentgrid.appserver.contentstore.api.range.UnsatisfiableContentRangeException;
import com.contentgrid.appserver.domain.authorization.AuthorizationContext;
import com.contentgrid.appserver.domain.data.DataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.NullDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.NullDataEntry;
import com.contentgrid.appserver.domain.data.InvalidPropertyDataException;
import com.contentgrid.appserver.domain.data.MapRequestInputData;
import com.contentgrid.appserver.domain.values.EntityId;
import com.contentgrid.appserver.application.model.values.EntityId;
import com.contentgrid.appserver.domain.values.EntityRequest;
import com.contentgrid.appserver.domain.values.User;
import com.contentgrid.appserver.domain.values.version.Version;
import com.contentgrid.appserver.domain.values.version.VersionConstraint;
import com.contentgrid.appserver.query.engine.api.data.CompositeAttributeData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.contentgrid.appserver.domain.paging.ResultSlice;
import com.contentgrid.appserver.domain.paging.cursor.CursorCodec.CursorDecodeException;
import com.contentgrid.appserver.domain.paging.cursor.EncodedCursorPagination;
import com.contentgrid.appserver.domain.values.EntityId;
import com.contentgrid.appserver.application.model.values.EntityId;
import com.contentgrid.appserver.domain.values.EntityRequest;
import com.contentgrid.appserver.domain.values.RelationRequest;
import com.contentgrid.appserver.query.engine.api.exception.EntityIdNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import com.contentgrid.appserver.application.model.values.EntityName;
import com.contentgrid.appserver.contentstore.api.ContentStore;
import com.contentgrid.appserver.domain.authorization.AuthorizationContext;
import com.contentgrid.appserver.domain.data.DataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.PlainDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.PlainDataEntry;
import com.contentgrid.appserver.domain.data.EntityInstance;
import com.contentgrid.appserver.domain.data.InvalidPropertyDataException;
import com.contentgrid.appserver.domain.data.RelationTarget;
Expand Down Expand Up @@ -35,7 +35,7 @@
import com.contentgrid.appserver.domain.paging.cursor.CursorCodec;
import com.contentgrid.appserver.domain.paging.cursor.EncodedCursorPagination;
import com.contentgrid.appserver.domain.paging.cursor.EncodedCursorSupport;
import com.contentgrid.appserver.domain.values.EntityId;
import com.contentgrid.appserver.application.model.values.EntityId;
import com.contentgrid.appserver.domain.values.EntityIdentity;
import com.contentgrid.appserver.domain.values.EntityRequest;
import com.contentgrid.appserver.domain.values.ItemCount;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.contentgrid.appserver.domain;

import com.contentgrid.appserver.application.model.values.AttributeName;
import com.contentgrid.appserver.domain.data.DataEntry.PlainDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.PlainDataEntry;
import com.contentgrid.appserver.domain.data.EntityInstance;
import com.contentgrid.appserver.domain.values.EntityIdentity;
import com.contentgrid.appserver.query.engine.api.data.AttributeData;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.contentgrid.appserver.domain.data;

import com.contentgrid.appserver.domain.data.DataEntry.PlainDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.PlainDataEntry;
import com.contentgrid.appserver.domain.values.EntityIdentity;
import java.util.SequencedMap;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.contentgrid.appserver.domain.data;

import com.contentgrid.appserver.domain.data.DataEntry.BooleanDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.DecimalDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.InstantDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.ListDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.LocalDateDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.LongDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.MapDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.MissingDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.NullDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.PlainDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.StringDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.BooleanDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.DecimalDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.InstantDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.ListDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.LocalDateDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.LongDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.MapDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.MissingDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.NullDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.PlainDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.StringDataEntry;
import com.contentgrid.appserver.domain.data.type.DataType;
import com.contentgrid.appserver.domain.data.type.TechnicalDataType;
import java.math.BigDecimal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.contentgrid.appserver.domain.data;

import com.contentgrid.appserver.application.model.values.DataEntry;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.contentgrid.appserver.domain.data;

import com.contentgrid.appserver.application.model.values.DataEntry;
import java.util.Collections;
import java.util.List;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import com.contentgrid.appserver.application.model.attributes.SimpleAttribute;
import com.contentgrid.appserver.application.model.values.AttributePath;
import com.contentgrid.appserver.application.model.values.SimpleAttributePath;
import com.contentgrid.appserver.domain.data.DataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.MapDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.PlainDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.MapDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.PlainDataEntry;
import com.contentgrid.appserver.domain.data.InvalidDataException;
import com.contentgrid.appserver.domain.data.InvalidPropertyDataException;
import com.contentgrid.appserver.domain.data.validation.ValidationExceptionCollector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import com.contentgrid.appserver.application.model.attributes.ContentAttribute;
import com.contentgrid.appserver.application.model.attributes.SimpleAttribute;
import com.contentgrid.appserver.application.model.attributes.UserAttribute;
import com.contentgrid.appserver.domain.data.DataEntry.BooleanDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.DecimalDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.InstantDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.LocalDateDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.LongDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.MapDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.NullDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.PlainDataEntry;
import com.contentgrid.appserver.domain.data.DataEntry.StringDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.BooleanDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.DecimalDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.InstantDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.LocalDateDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.LongDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.MapDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.NullDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.PlainDataEntry;
import com.contentgrid.appserver.application.model.values.DataEntry.StringDataEntry;
import com.contentgrid.appserver.query.engine.api.data.AttributeData;
import com.contentgrid.appserver.query.engine.api.data.CompositeAttributeData;
import com.contentgrid.appserver.query.engine.api.data.SimpleAttributeData;
Expand Down
Loading