-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow instant publish of modified data fields
- Loading branch information
1 parent
2b56c4e
commit 15f2d21
Showing
9 changed files
with
671 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
modules/core/core-api/src/main/java/com/enonic/xp/node/PatchNodeParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.enonic.xp.node; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableSet; | ||
|
||
import com.enonic.xp.annotation.PublicApi; | ||
import com.enonic.xp.branch.Branch; | ||
import com.enonic.xp.branch.Branches; | ||
|
||
@PublicApi | ||
public final class PatchNodeParams | ||
{ | ||
private final NodeId id; | ||
|
||
private final NodePath path; | ||
|
||
private final NodeEditor editor; | ||
|
||
private final Branches branches; | ||
|
||
|
||
private PatchNodeParams( final Builder builder ) | ||
{ | ||
this.id = builder.id; | ||
this.path = builder.path; | ||
this.editor = builder.editor; | ||
branches = Branches.from( builder.branches.build() ); | ||
|
||
} | ||
|
||
public static Builder create() | ||
{ | ||
return new Builder(); | ||
} | ||
|
||
public NodeId getId() | ||
{ | ||
return id; | ||
} | ||
|
||
public NodePath getPath() | ||
{ | ||
return path; | ||
} | ||
|
||
public NodeEditor getEditor() | ||
{ | ||
return editor; | ||
} | ||
|
||
public Branches getBranches() | ||
{ | ||
return branches; | ||
} | ||
|
||
|
||
public static final class Builder | ||
{ | ||
private final ImmutableSet.Builder<Branch> branches = ImmutableSet.builder(); | ||
|
||
private NodeId id; | ||
|
||
private NodePath path; | ||
|
||
private NodeEditor editor; | ||
|
||
|
||
private Builder() | ||
{ | ||
} | ||
|
||
public Builder id( final NodeId id ) | ||
{ | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public Builder path( final NodePath path ) | ||
{ | ||
this.path = path; | ||
return this; | ||
} | ||
|
||
public Builder editor( final NodeEditor editor ) | ||
{ | ||
this.editor = editor; | ||
return this; | ||
} | ||
|
||
public Builder addBranches( final Branches branches ) | ||
{ | ||
this.branches.addAll( branches ); | ||
return this; | ||
} | ||
|
||
public PatchNodeParams build() | ||
{ | ||
this.validate(); | ||
return new PatchNodeParams( this ); | ||
} | ||
|
||
private void validate() | ||
{ | ||
if ( this.id == null && this.path == null ) | ||
{ | ||
throw new NullPointerException( "id and path cannot be both null" ); | ||
} | ||
Preconditions.checkNotNull( this.editor, "editor cannot be null" ); | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
modules/core/core-api/src/main/java/com/enonic/xp/node/PatchNodeResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.enonic.xp.node; | ||
|
||
import java.util.List; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import com.enonic.xp.annotation.PublicApi; | ||
import com.enonic.xp.branch.Branch; | ||
|
||
@PublicApi | ||
public final class PatchNodeResult | ||
{ | ||
private final NodeId nodeId; | ||
|
||
private final List<BranchResult> results; | ||
|
||
private PatchNodeResult( Builder builder ) | ||
{ | ||
this.nodeId = builder.nodeId; | ||
this.results = builder.results.build(); | ||
|
||
} | ||
|
||
public static Builder create() | ||
{ | ||
return new Builder(); | ||
} | ||
|
||
public NodeId getNodeId() | ||
{ | ||
return nodeId; | ||
} | ||
|
||
public List<BranchResult> getResults() | ||
{ | ||
return results; | ||
} | ||
|
||
public Node getResult( final Branch branch ) | ||
{ | ||
return results.stream().filter( br -> br.branch.equals( branch ) ).map( BranchResult::node ).findAny().orElse( null ); | ||
} | ||
|
||
public record BranchResult(Branch branch, Node node) | ||
{ | ||
|
||
} | ||
|
||
public static final class Builder | ||
{ | ||
private final ImmutableList.Builder<BranchResult> results = ImmutableList.builder(); | ||
|
||
private NodeId nodeId; | ||
|
||
private Builder() | ||
{ | ||
} | ||
|
||
public Builder addResult( Branch branch, Node node ) | ||
{ | ||
if ( nodeId == null ) | ||
{ | ||
nodeId = node.id(); | ||
} | ||
else if ( !nodeId.equals( node.id() ) ) | ||
{ | ||
throw new IllegalArgumentException( "All nodes must have the same id" ); | ||
} | ||
|
||
results.add( new BranchResult( branch, node ) ); | ||
return this; | ||
} | ||
|
||
public PatchNodeResult build() | ||
{ | ||
return new PatchNodeResult( this ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.