Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mojo2012 committed Nov 29, 2018
2 parents e1400c3 + 7f46141 commit 61bf2f5
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 39 deletions.
3 changes: 2 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ The supported modifiers are:
* `lang=<iso code>`: the `Locale` used for localized properties
* `PrimitiveValueResolver` and `Local*Resolver` support the `format` modifier to set a custom date format.

> (Custom) resolvers have access to both the selector and the modifers!
> (Custom) resolvers have access to both the selector and the modifiers!
> Allowed characters in the modifiers part are: letters, numbers and `,.:;+*'#&%$§!/ _-=`
Here is a quick demonstration of references and default values:

Expand Down
6 changes: 3 additions & 3 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ or

```bash
java -jar target/<jar-with-dependencies.jar> --core.setup.typesystem.initialize=true --core.setup.import.initialdata=true --core.setup.import.sampledata=true --add-opens java.base/java.lang=ALL-UNNAMED
``
```

> Use the JVM parameter `--add-opens java.base/java.lang=ALL-UNNAMED` to bypass Java "Illegal reflective access" warnings, when starting spot with `java -jar` or from an IDE.
Expand Down Expand Up @@ -942,8 +942,8 @@ Now that we have an endpoint we just need a template for our page (/resources/te
<title th:text="${pageTitle}">Party sample page</title>
<link rel="canonical" th:href="${canonicalUrl}">

<link rel="stylesheet" href="//cdn.rawgit.com/necolas/normalize.css/master/normalize.css">
<link rel="stylesheet" href="//cdn.rawgit.com/milligram/milligram/master/dist/milligram.min.css">
<link rel="stylesheet" href="////necolas.github.io/normalize.css/latest/normalize.css">
<link rel="stylesheet" href="//raw.githubusercontent.com/milligram/milligram/master/dist/milligram.min.css">

<style>
body {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ public class DefaultImpexImportStrategy extends AbstractService implements Impex
/** Constant <code>COLLECTION_VALUE_SEPARATOR=","</code> */
public static final String COLLECTION_VALUE_SEPARATOR = ",";

// ^[\s]{0,}([a-zA-Z0-9]{2,})(\({0,1}[a-zA-Z0-9,\(\)]{0,}\){0,1})(\[{0,1}[a-zA-Z0-9,._\-\=]{0,}\]{0,1})
protected static final Pattern PATTERN_COLUMN_DEFINITION = Pattern
.compile("^[\\s]{0,}([a-zA-Z0-9]{2,})(\\({0,1}[a-zA-Z0-9&,\\(\\)]{0,}\\){0,1})(\\[{0,1}[a-zA-Z0-9,._\\-\\=]{0,}\\]{0,1})");
protected static final Pattern PATTERN_COLUMN_DEFINITION = Pattern.compile(
"^[\\s]{0,}([a-zA-Z0-9]{2,})\\s{0,}(\\({0,1}\\s{0,}[a-zA-Z0-9&,\\(\\)\\s]{0,}\\s{0,}\\){0,1})\\s{0,}(\\s{0,}\\[{0,1}[a-zA-Z0-9,.:;+\\*'#&%$§!\\/\\s_\\-\\=]{0,}\\s{0,}\\]{0,1})");

protected static final String ITEM_REFERENCE_MARKER = "&ref";
protected static final Pattern PATTERN_ITEM_REFERENCE_COLUMN_DEFINITION = Pattern.compile("\\s{0,}\\([\\s]{0,}" + ITEM_REFERENCE_MARKER + "[\\s]{0,}\\)");
Expand Down Expand Up @@ -171,11 +170,11 @@ protected List<WorkUnit> transformImpex(final List<String> fileContent) throws I
return workUnits;
}

private Optional<ImpexCommand> parseImpexCommand(String stringCommand) {
private Optional<ImpexCommand> parseImpexCommand(final String stringCommand) {
ImpexCommand command = null;
try {
command = ImpexCommand.valueOf(stringCommand.toUpperCase(Locale.getDefault()));
} catch (IllegalArgumentException e) {
} catch (final IllegalArgumentException e) {
// ignore not found
}

Expand Down Expand Up @@ -222,7 +221,7 @@ protected void importWorkUnits(final List<WorkUnit> workUnits, final ImportConfi

final List<JpqlQuery<Void>> itemsToRemove = new ArrayList<>();

var itemReferences = new HashMap<String, Item>();
final var itemReferences = new HashMap<String, Item>();

for (final WorkUnit unit : workUnits) {
List<String> currentRow = null;
Expand Down Expand Up @@ -440,7 +439,7 @@ private Map<String, Object> getUniqueAttributValues(final List<ColumnDefinition>

for (final ColumnDefinition col : headerColumns) {
// only look at the unique properties
if (BooleanUtils.toBoolean((String) col.getModifiers().get("unique"))) {
if (BooleanUtils.toBoolean(col.getModifiers().get("unique"))) {
if (isCollectionType(col) || isMapType(col)) {
final String message = "Columns with type Collection or Map cannot be used as unique identifiers.";

Expand Down Expand Up @@ -573,7 +572,7 @@ private ImpexMergeMode getMergeMode(final ColumnDefinition columnDefinition) {
}

private Object resolveValue(final String value, final Class<?> type, final List<Class<?>> genericArguments, final ColumnDefinition columnDefinition,
HashMap<String, Item> itemReferences) {
final HashMap<String, Item> itemReferences) {

Object ret = null;

Expand Down Expand Up @@ -612,11 +611,12 @@ private Object resolveValue(final String value, final Class<?> type, final List<
return ret;
}

private Object resolveSingleValue(final String value, final Class<?> type, final ColumnDefinition columnDefinition, HashMap<String, Item> itemReferences) {
private Object resolveSingleValue(final String value, final Class<?> type, final ColumnDefinition columnDefinition,
final HashMap<String, Item> itemReferences) {

if (StringUtils.isNotBlank(columnDefinition.getValueResolutionDescriptor())) {

var desc = columnDefinition.getValueResolutionDescriptor();
final var desc = columnDefinition.getValueResolutionDescriptor();

// this is not a item refenrence path but a virtual reference
if (PATTERN_ITEM_REFERENCE_COLUMN_DEFINITION.matcher(desc).matches()) {
Expand All @@ -625,7 +625,7 @@ private Object resolveSingleValue(final String value, final Class<?> type, final
return referenceValueResolver.resolve(value, type, null, columnDefinition);
}
} else {
String resolverClass = columnDefinition.getModifiers().get("resolver");
final String resolverClass = columnDefinition.getModifiers().get("resolver");
if (StringUtils.isNotBlank(resolverClass)) {
final ImpexValueResolver resolver = impexValueResolvers.get(resolverClass);

Expand All @@ -636,7 +636,7 @@ private Object resolveSingleValue(final String value, final Class<?> type, final
}
}

protected List<ColumnDefinition> parseHeaderColumns(final List<String> columns, WorkUnit unit) {
protected List<ColumnDefinition> parseHeaderColumns(final List<String> columns, final WorkUnit unit) {
final List<ColumnDefinition> parsedColumns = new ArrayList<>();

boolean isFirst = true;
Expand All @@ -647,7 +647,7 @@ protected List<ColumnDefinition> parseHeaderColumns(final List<String> columns,
continue;
}

String trimmedCol = col.replace(" ", "");
final String trimmedCol = col.trim();

if (StringUtils.isBlank(trimmedCol)) {
continue;
Expand All @@ -658,9 +658,9 @@ protected List<ColumnDefinition> parseHeaderColumns(final List<String> columns,
final Matcher columnMatcher = PATTERN_COLUMN_DEFINITION.matcher(trimmedCol);

if (columnMatcher.matches()) {
final String propertyName = columnMatcher.group(1);
final String valueResolutionDescriptor = columnMatcher.group(2);
final String modifiers = columnMatcher.group(3);
final String propertyName = columnMatcher.group(1).trim();
final String valueResolutionDescriptor = columnMatcher.group(2).trim();
final String modifiers = columnMatcher.group(3).trim();

colDef.setPropertyName(propertyName);
colDef.setValueResolutionDescriptor(valueResolutionDescriptor);
Expand All @@ -683,17 +683,15 @@ protected Map<String, String> parseModifiers(final String modifiers) {
if (StringUtils.isNotBlank(modifiers)) {
final Map<String, String> parsedModifiers = new HashMap<>();

// remove all spaces
String trimmedModifiers = modifiers.replace(" ", "");

final String[] kvPairs = StringUtils.removeAll(trimmedModifiers, "[\\[\\]]").split(COLLECTION_VALUE_SEPARATOR);
final String trimmedModifiers = StringUtils.trimToEmpty(modifiers).replace("[", "").replace("]", "");
final String[] kvPairs = trimmedModifiers.split(COLLECTION_VALUE_SEPARATOR);

if (kvPairs.length > 0) {
Stream.of(kvPairs).forEach(kv -> {
final String[] kvSplit = StringUtils.split(kv, '=');

if (kvSplit.length == 2) {
parsedModifiers.put(StringUtils.trim(kvSplit[0]), StringUtils.trim(kvSplit[1]));
parsedModifiers.put(StringUtils.trim(kvSplit[0]), StringUtils.trimToEmpty(kvSplit[1]));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
INSERT USER ; uid[unique=true] ; &ref
; refUser ; ref-user

INSERT UserGroup ; uid[unique=true] ; members(&ref)
; refGroup ; ref-user
4 changes: 2 additions & 2 deletions spot-instrumentation/src/main/resources/META-INF/aop.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>

<!-- -debug -->
<weaver options="-Xreweavable -showWeaveInfo -Xlint:ignore -Xset:weaveJavaxPackages=true">
<!-- -debug -showWeaveInfo -->
<weaver options="-Xreweavable -Xlint:ignore -Xset:weaveJavaxPackages=true">
<!-- only weave classes in our application-specific packages -->
<include within="*"/>
</weaver>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.spotnext.itemtype.core.user.User;
import io.spotnext.itemtype.core.user.UserGroup;
import io.spotnext.sample.filters.IsAdminFilter;
import io.spotnext.sample.types.itemtypes.Party;
import io.spotnext.sample.types.party.Party;
import spark.Request;
import spark.Response;
import spark.route.HttpMethod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package io.spotnext.sample.interceptor;

import java.time.LocalDate;
import java.time.LocalDateTime;

import org.springframework.stereotype.Service;

import io.spotnext.core.infrastructure.exception.ModelValidationException;
import io.spotnext.core.infrastructure.interceptor.ItemValidateInterceptor;
import io.spotnext.core.infrastructure.interceptor.impl.AbstractItemInterceptor;
import io.spotnext.sample.types.itemtypes.Party;
import io.spotnext.sample.types.party.Party;

@Service
public class PartyValidateInterceptor extends AbstractItemInterceptor<Party> implements ItemValidateInterceptor<Party> {

@Override
public void onValidate(final Party item) throws ModelValidationException {
if (item.isFixed()
&& (item.getLocation() == null || (item.getDate() == null || item.getDate().isBefore(LocalDate.now()))
&& (item.getLocation() == null || (item.getDate() == null || item.getDate().isBefore(LocalDateTime.now()))
|| item.getInvitedGuests().size() == 0)) {
throw new ModelValidationException(
"Party cannot be fixed as not all necessary properties (date, location, invitedGuests) are defined yet.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.spotnext.core.infrastructure.event.ItemModificationEvent;
import io.spotnext.itemtype.core.user.User;
import io.spotnext.sample.service.EmailService;
import io.spotnext.sample.types.itemtypes.Party;
import io.spotnext.sample.types.party.Party;

@Service
public class PartyModificationListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
INSERT_UPDATE Party;title [ unique = true ] ; date[format=dd.MM.yyyy]
;test-party ; 01.09.2019
INSERT_UPDATE Party;title [ unique = true ] ; date[format=dd.MM.yyyy HH:mm]
;test-party ; 01.09.2019 18:00
6 changes: 3 additions & 3 deletions spot-sample-simple/src/main/resources/sample-itemtypes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</properties>
</type>

<type name="Party" package="io.spotnext.sample.types.itemtypes">
<type name="Party" package="io.spotnext.sample.types.party">
<properties>
<property name="title" type="String">
<description>The unique title of the party</description>
Expand All @@ -67,8 +67,8 @@
<property name="location" type="Address">
<description>The location the party will take place</description>
</property>
<property name="date" type="LocalDate">
<description>The date the party will take place</description>
<property name="date" type="LocalDateTime">
<description>The date and time the party will take place</description>
</property>
<property name="fixed" type="boolean">
<description>Defines that the party has been fixed and should not be changed anymore.</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.spotnext.sample.integrationtests;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Collections;

import org.junit.Assert;
Expand All @@ -18,7 +19,7 @@
import io.spotnext.core.testing.IntegrationTest;
import io.spotnext.itemtype.core.user.User;
import io.spotnext.sample.SampleInit;
import io.spotnext.sample.types.itemtypes.Party;
import io.spotnext.sample.types.party.Party;

@IntegrationTest(initClass = SampleInit.class)
@SpringBootTest(classes = { SampleInit.class, CoreInit.class })
Expand All @@ -37,7 +38,7 @@ protected void prepareTest() {

final Party party = modelService.create(Party.class);
party.setTitle(PARTY_TITLE);
party.setDate(LocalDate.of(2019, 1, 1));
party.setDate(LocalDateTime.of(2019, 1, 1, 18, 0));

// collections are never null!
party.getInvitedGuests().add(guest);
Expand Down

0 comments on commit 61bf2f5

Please sign in to comment.