Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
rymsha committed Feb 24, 2025
1 parent c029739 commit 6ddf512
Show file tree
Hide file tree
Showing 52 changed files with 240 additions and 660 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;

import com.enonic.xp.core.internal.json.ObjectMapperHelper;
import com.enonic.xp.event.Event;
import com.enonic.xp.json.ObjectMapperHelper;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.junit.jupiter.api.Test;

import com.enonic.xp.json.ObjectMapperHelper;
import com.enonic.xp.core.internal.json.ObjectMapperHelper;
import com.enonic.xp.server.VersionInfo;
import com.enonic.xp.web.WebResponse;

Expand Down
1 change: 1 addition & 0 deletions modules/app/app-system/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dependencies {
compileOnly project( ':core:core-api' )
compileOnly project( ':script:script-api' )
compileOnly project( ':core:core-internal' )

testImplementation project( ':tools:testing' )
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import com.enonic.xp.app.system.listener.VacuumListenerImpl;
import com.enonic.xp.json.ObjectMapperHelper;
import com.enonic.xp.core.internal.json.ObjectMapperHelper;
import com.enonic.xp.script.bean.BeanContext;
import com.enonic.xp.script.bean.ScriptBean;
import com.enonic.xp.task.ProgressReporter;
Expand Down
2 changes: 1 addition & 1 deletion modules/core/core-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ dependencies {

implementation project( ':core:core-internal' )

implementation libs.jackson.datatype.jsr310
implementation libs.jparsec

testFixturesImplementation libs.junit.jupiter.api
testFixturesImplementation libs.mockito.core
testFixturesImplementation project( ':core:core-internal' )

testImplementation project( ':core:core-internal' )
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
Expand Down Expand Up @@ -325,7 +327,7 @@ public Property setProperty( final PropertyPath path, final Value value )
* If the property with values exists and is not a type of valueType given, an exception will be thrown.
* Difference with setProperty is that this method does not set the property value.
*
* @param name property name
* @param name property name
* @param valueType expected value type
*/
public void ensureProperty( final String name, final ValueType valueType )
Expand Down Expand Up @@ -675,9 +677,7 @@ public Property[] addStrings( final String name, final String... values )

public Property[] addStrings( final String name, final Collection<String> values )
{
return values.stream().
map( ( value ) -> addProperty( name, ValueFactory.newString( value ) ) ).
toArray( Property[]::new );
return values.stream().map( ( value ) -> addProperty( name, ValueFactory.newString( value ) ) ).toArray( Property[]::new );
}

// setting xml
Expand Down Expand Up @@ -1436,4 +1436,65 @@ private String enumToString( final Enum e )
return e.toString();
}

static PropertySet fromMap( Map<String, ?> map )
{
PropertySet propertySet = new PropertySet();
translate( map, propertySet );
return propertySet;
}

static void translate( final Map<String, ?> json, final PropertySet into )
{
for ( Map.Entry<String, ?> field : json.entrySet() )
{
addValue( into, field.getKey(), field.getValue() );
}
}

private static void addValue( final PropertySet parent, final String key, final Object value )
{
if ( value instanceof List )
{
for ( final Object objNode : (List<?>) value )
{
addValue( parent, key, objNode );
}
}
else if ( value instanceof Map )
{
final PropertySet parentSet = parent.addSet( key );
for ( final Map.Entry<String, ?> next : ( (Map<String, ?>) value ).entrySet() )
{
addValue( parentSet, next.getKey(), next.getValue() );
}
}
else
{
parent.addProperty( key, resolveCoreValue( value ) );
}
}

private static Value resolveCoreValue( final Object value )
{
return switch ( value )
{
case String s -> ValueFactory.newString( s );
case Integer i -> ValueFactory.newLong( i.longValue() );
case Float v -> ValueFactory.newDouble( v.doubleValue() );
case Double v -> ValueFactory.newDouble( v );

Check warning on line 1484 in modules/core/core-api/src/main/java/com/enonic/xp/data/PropertySet.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-api/src/main/java/com/enonic/xp/data/PropertySet.java#L1482-L1484

Added lines #L1482 - L1484 were not covered by tests
case Boolean b -> ValueFactory.newBoolean( b );
case Long l -> ValueFactory.newLong( l );
case Instant instant -> ValueFactory.newDateTime( instant );
case Date date -> ValueFactory.newDateTime( date.toInstant() );
case LocalTime localTime -> ValueFactory.newLocalTime( localTime );
case LocalDateTime localDateTime -> ValueFactory.newLocalDateTime( localDateTime );
case LocalDate localDate -> ValueFactory.newLocalDate( localDate );
case GeoPoint geoPoint -> ValueFactory.newGeoPoint( geoPoint );
case Reference reference -> ValueFactory.newReference( reference );
case BinaryReference binaryReference -> ValueFactory.newBinaryReference( binaryReference );
case Link link -> ValueFactory.newLink( link );
case null -> ValueFactory.newString( null );
default -> ValueFactory.newString( value.toString() );

Check warning on line 1497 in modules/core/core-api/src/main/java/com/enonic/xp/data/PropertySet.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-api/src/main/java/com/enonic/xp/data/PropertySet.java#L1486-L1497

Added lines #L1486 - L1497 were not covered by tests
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public Map<String, Object> toMap()
return root.toMap();
}

public static PropertyTree fromMap( Map<String, ?> map )
{
return new PropertyTree( PropertySet.fromMap( map ) );
}

@Override
public boolean equals( final Object o )
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.enonic.xp.issue;

import com.fasterxml.jackson.annotation.JsonIgnore;

import com.enonic.xp.content.ContentIds;

@Deprecated
public final class FindIssuesParams
{
private final IssueStatus status;
Expand Down Expand Up @@ -61,7 +61,6 @@ public Integer getSize()
return size;
}

@JsonIgnore
public ContentIds getItems()
{
return items;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,59 @@
package com.enonic.xp.repository;

import java.net.URL;
import java.util.Map;

import com.fasterxml.jackson.databind.JsonNode;

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.data.PropertyTree;
import com.enonic.xp.util.JsonHelper;
import com.enonic.xp.core.internal.json.JsonHelper;

@PublicApi
public class IndexMapping
{
private final JsonNode jsonNode;

@Deprecated
public IndexMapping( final JsonNode resourceNode )
{
this.jsonNode = resourceNode;
}

Check warning on line 21 in modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexMapping.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexMapping.java#L19-L21

Added lines #L19 - L21 were not covered by tests

private IndexMapping( final JsonNode resourceNode, boolean ignore )
{
this.jsonNode = resourceNode;
}

@Deprecated
public static IndexMapping from( final PropertyTree propertyTree )
{
return new IndexMapping( JsonHelper.from( propertyTree ) );
return new IndexMapping( JsonHelper.from( propertyTree.toMap() ), false );

Check warning on line 31 in modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexMapping.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexMapping.java#L31

Added line #L31 was not covered by tests
}

@Deprecated
public static IndexMapping from( final URL url )
{
return new IndexMapping( JsonHelper.from( url ) );
return new IndexMapping( JsonHelper.from( url ), false );

Check warning on line 37 in modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexMapping.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexMapping.java#L37

Added line #L37 was not covered by tests
}

@Deprecated
public static IndexMapping from( final String string )
{
return new IndexMapping( JsonHelper.from( string ) );
return new IndexMapping( JsonHelper.from( string ), false );

Check warning on line 43 in modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexMapping.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexMapping.java#L43

Added line #L43 was not covered by tests
}

public IndexMapping( final JsonNode resourceNode )
public static IndexMapping from( final Map<String, Object> data )
{
this.jsonNode = resourceNode;
return new IndexMapping( JsonHelper.from( data ), false );
}

public Map<String, Object> getData()
{
return JsonHelper.toMap( jsonNode );
}

@Deprecated
public JsonNode getNode()
{
return jsonNode;
Expand All @@ -43,4 +64,11 @@ public String getAsString()
return this.jsonNode.toString();
}

public IndexMapping merge( final IndexMapping with )
{
final JsonNode newJsonNode = this.jsonNode.deepCopy();
JsonHelper.merge( newJsonNode, with.jsonNode );

Check warning on line 70 in modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexMapping.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexMapping.java#L69-L70

Added lines #L69 - L70 were not covered by tests

return new IndexMapping( newJsonNode, false );

Check warning on line 72 in modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexMapping.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexMapping.java#L72

Added line #L72 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,61 @@

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.data.PropertyTree;
import com.enonic.xp.util.JsonHelper;
import com.enonic.xp.core.internal.json.JsonHelper;

@PublicApi
public class IndexSettings
{
private final JsonNode jsonNode;

@Deprecated
public IndexSettings( final JsonNode resourceNode )
{
this.jsonNode = resourceNode;
}

Check warning on line 21 in modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexSettings.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexSettings.java#L19-L21

Added lines #L19 - L21 were not covered by tests

private IndexSettings( final JsonNode resourceNode, final boolean ignore)
{
this.jsonNode = resourceNode;
}

@Deprecated
public static IndexSettings from( final PropertyTree propertyTree )
{
return new IndexSettings( JsonHelper.from( propertyTree ) );
return new IndexSettings( JsonHelper.from( propertyTree.toMap() ), false );

Check warning on line 31 in modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexSettings.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexSettings.java#L31

Added line #L31 was not covered by tests
}

@Deprecated
public static IndexSettings from( final URL url )
{
return new IndexSettings( JsonHelper.from( url ) );
return new IndexSettings( JsonHelper.from( url ), false );

Check warning on line 37 in modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexSettings.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexSettings.java#L37

Added line #L37 was not covered by tests
}

@Deprecated
public static IndexSettings from( final String string )
{
return new IndexSettings( JsonHelper.from( string ) );
return new IndexSettings( JsonHelper.from( string ), false );

Check warning on line 43 in modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexSettings.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-api/src/main/java/com/enonic/xp/repository/IndexSettings.java#L43

Added line #L43 was not covered by tests
}

public static IndexSettings from( final Map<String, Object> settings )
{
return new IndexSettings( JsonHelper.from( settings ) );
return new IndexSettings( JsonHelper.from( settings ), false );
}

public IndexSettings( final JsonNode resourceNode )
public IndexSettings merge( final IndexSettings with )
{
this.jsonNode = resourceNode;
final JsonNode newJsonNode = this.jsonNode.deepCopy();
JsonHelper.merge( newJsonNode, with.jsonNode );

return new IndexSettings( newJsonNode, false );
}

public Map<String, Object> getData()
{
return JsonHelper.toMap( jsonNode );
}

@Deprecated
public JsonNode getNode()
{
return jsonNode;
Expand Down
Loading

0 comments on commit 6ddf512

Please sign in to comment.