diff --git a/src/main/java/de/metas/ui/web/pattribute/ASIRepository.java b/src/main/java/de/metas/ui/web/pattribute/ASIRepository.java index 70f64fec9..8a28b38b9 100644 --- a/src/main/java/de/metas/ui/web/pattribute/ASIRepository.java +++ b/src/main/java/de/metas/ui/web/pattribute/ASIRepository.java @@ -23,6 +23,7 @@ import de.metas.ui.web.pattribute.json.JSONCreateASIRequest; import de.metas.ui.web.window.datatypes.DocumentId; import de.metas.ui.web.window.datatypes.DocumentPath; +import de.metas.ui.web.window.datatypes.DocumentType; import de.metas.ui.web.window.datatypes.LookupValue; import de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent; import de.metas.ui.web.window.model.Document; @@ -109,15 +110,32 @@ public ASIDocument createNewFrom(final JSONCreateASIRequest request) private ASIEditingInfo createASIEditingInfo(final JSONCreateASIRequest request) { final DocumentPath documentPath = request.getSource().toSingleDocumentPath(); - return documentsCollection.forDocumentReadonly(documentPath, document -> { - final int productId = document.asEvaluatee().get_ValueAsInt("M_Product_ID", -1); - final boolean isSOTrx = document.asEvaluatee().get_ValueAsBoolean("IsSOTrx", true); + if (documentPath.getDocumentType() == DocumentType.Window) + { + return documentsCollection.forDocumentReadonly(documentPath, document -> { + final int productId = document.asEvaluatee().get_ValueAsInt("M_Product_ID", -1); + final boolean isSOTrx = document.asEvaluatee().get_ValueAsBoolean("IsSOTrx", true); + + final int attributeSetInstanceId = request.getTemplateId(); + final String callerTableName = document.getEntityDescriptor().getTableNameOrNull(); + final int callerColumnId = -1; // FIXME implement + return ASIEditingInfo.of(productId, attributeSetInstanceId, callerTableName, callerColumnId, isSOTrx); + }); + } + else if (documentPath.getDocumentType() == DocumentType.Process) + { + final int productId = -1; + final boolean isSOTrx = true; final int attributeSetInstanceId = request.getTemplateId(); - final String callerTableName = document.getEntityDescriptor().getTableNameOrNull(); - final int callerColumnId = -1; // FIXME implement + final String callerTableName = null; + final int callerColumnId = -1; // N/A return ASIEditingInfo.of(productId, attributeSetInstanceId, callerTableName, callerColumnId, isSOTrx); - }); + } + else + { + throw new IllegalStateException("Cannot create ASI editing info from " + documentPath); + } } public ASILayout getLayout(final DocumentId asiDocId) diff --git a/src/main/java/de/metas/ui/web/process/ProcessId.java b/src/main/java/de/metas/ui/web/process/ProcessId.java index 9bbe4a136..769635dd0 100644 --- a/src/main/java/de/metas/ui/web/process/ProcessId.java +++ b/src/main/java/de/metas/ui/web/process/ProcessId.java @@ -1,5 +1,7 @@ package de.metas.ui.web.process; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; import com.google.common.base.Preconditions; import de.metas.ui.web.window.datatypes.DocumentId; @@ -59,6 +61,7 @@ public static final ProcessId ofAD_Process_ID(final int adProcessId) private final String processId; private transient int processIdAsInt = 0; + @JsonCreator private ProcessId(final String json) { super(); @@ -101,6 +104,7 @@ public String toString() return toJson(); } + @JsonValue public String toJson() { return json; diff --git a/src/main/java/de/metas/ui/web/window/datatypes/DocumentPath.java b/src/main/java/de/metas/ui/web/window/datatypes/DocumentPath.java index a7997d275..ac11b88a9 100644 --- a/src/main/java/de/metas/ui/web/window/datatypes/DocumentPath.java +++ b/src/main/java/de/metas/ui/web/window/datatypes/DocumentPath.java @@ -66,7 +66,7 @@ public static final DocumentPath rootDocumentPath(@NonNull final WindowId window } return new DocumentPath(DocumentType.Window, windowId.toDocumentId(), documentId); } - + public static final DocumentPath rootDocumentPath(@NonNull final WindowId windowId, @NonNull final DocumentId documentId) { if (documentId.isNew()) @@ -76,7 +76,6 @@ public static final DocumentPath rootDocumentPath(@NonNull final WindowId window return new DocumentPath(DocumentType.Window, windowId.toDocumentId(), documentId); } - public static final DocumentPath rootDocumentPath(final DocumentType documentType, final DocumentId documentTypeId, final DocumentId documentId) { if (documentId == null || documentId.isNew()) @@ -136,13 +135,13 @@ public static final DocumentPath includedDocumentPath(final WindowId windowId, f /** * Creates the path of a single document (root document or included document). */ - public static final DocumentPath singleWindowDocumentPath(@NonNull final WindowId windowId, final String idStr, final String detailId, final String rowIdStr) + public static final DocumentPath singleWindowDocumentPath(@NonNull final WindowId windowId, final DocumentId id, final DetailId detailId, final DocumentId rowId) { return builder() .setDocumentType(windowId) - .setDocumentId(idStr) + .setDocumentId(id) .setDetailId(detailId) - .setRowId(rowIdStr) + .setRowId(rowId) .build(); } @@ -525,7 +524,13 @@ public Builder setDocumentType(@NonNull final WindowId windowId) public Builder setDocumentId(final String documentIdStr) { - documentId = DocumentId.fromNullable(documentIdStr); + setDocumentId(DocumentId.fromNullable(documentIdStr)); + return this; + } + + public Builder setDocumentId(final DocumentId documentId) + { + this.documentId = documentId; return this; } @@ -537,7 +542,13 @@ public Builder allowNewDocumentId() public Builder setDetailId(final String detailIdStr) { - detailId = DetailId.fromJson(detailIdStr); + setDetailId(DetailId.fromJson(detailIdStr)); + return this; + } + + public Builder setDetailId(final DetailId detailId) + { + this.detailId = detailId; return this; } diff --git a/src/main/java/de/metas/ui/web/window/datatypes/json/JSONDocumentPath.java b/src/main/java/de/metas/ui/web/window/datatypes/json/JSONDocumentPath.java index 771cf499f..d1c58b5aa 100644 --- a/src/main/java/de/metas/ui/web/window/datatypes/json/JSONDocumentPath.java +++ b/src/main/java/de/metas/ui/web/window/datatypes/json/JSONDocumentPath.java @@ -9,8 +9,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.MoreObjects; +import de.metas.ui.web.process.ProcessId; +import de.metas.ui.web.window.datatypes.DocumentId; import de.metas.ui.web.window.datatypes.DocumentPath; +import de.metas.ui.web.window.datatypes.DocumentType; import de.metas.ui.web.window.datatypes.WindowId; +import de.metas.ui.web.window.descriptor.DetailId; /* * #%L @@ -25,11 +29,11 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public - * License along with this program. If not, see + * License along with this program. If not, see * . * #L% */ @@ -38,21 +42,26 @@ @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) public class JSONDocumentPath implements Serializable { - @JsonProperty("documentType") + @JsonProperty("windowId") @JsonInclude(JsonInclude.Include.NON_EMPTY) private final WindowId windowId; + + @JsonProperty("processId") + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private final ProcessId processId; + // @JsonProperty("documentId") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private final String documentId; + private final DocumentId documentId; // @JsonProperty("tabid") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private final String tabid; + private final DetailId tabid; // @JsonProperty("rowId") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private final String rowId; + private final DocumentId rowId; @JsonProperty("fieldName") @JsonInclude(JsonInclude.Include.NON_EMPTY) @@ -60,14 +69,25 @@ public class JSONDocumentPath implements Serializable @JsonCreator private JSONDocumentPath( - @JsonProperty("documentType") final WindowId windowId // - , @JsonProperty("documentId") final String documentId // - , @JsonProperty("tabid") final String tabid // - , @JsonProperty("rowId") final String rowId // + @JsonProperty("documentType") @Deprecated final String documentType // + , @JsonProperty("windowId") final WindowId windowId // + , @JsonProperty("processId") final ProcessId processId // + , @JsonProperty("documentId") final DocumentId documentId // + , @JsonProperty("tabid") final DetailId tabid // + , @JsonProperty("rowId") final DocumentId rowId // , @JsonProperty("fieldName") final String fieldName) { - super(); - this.windowId = windowId; + if (windowId == null && processId == null) + { + this.windowId = WindowId.fromJson(documentType); + this.processId = null; + } + else + { + this.windowId = windowId; + this.processId = processId; + } + this.documentId = documentId; this.tabid = tabid; this.rowId = rowId; @@ -80,6 +100,7 @@ public String toString() return MoreObjects.toStringHelper(this) .omitNullValues() .add("windowId", windowId) + .add("processId", processId) .add("documentId", documentId) .add("tabid", tabid) .add("rowId", rowId) @@ -89,6 +110,17 @@ public String toString() public DocumentPath toSingleDocumentPath() { - return DocumentPath.singleWindowDocumentPath(windowId, documentId, tabid, rowId); + if (windowId != null) + { + return DocumentPath.singleWindowDocumentPath(windowId, documentId, tabid, rowId); + } + else if (processId != null) + { + return DocumentPath.rootDocumentPath(DocumentType.Process, processId.toDocumentId(), documentId); + } + else + { + throw new IllegalStateException("Cannot create single document path from " + this); + } } } diff --git a/src/main/java/de/metas/ui/web/window/descriptor/DetailId.java b/src/main/java/de/metas/ui/web/window/descriptor/DetailId.java index 1bffd4257..ab32f47eb 100644 --- a/src/main/java/de/metas/ui/web/window/descriptor/DetailId.java +++ b/src/main/java/de/metas/ui/web/window/descriptor/DetailId.java @@ -8,6 +8,7 @@ import org.adempiere.util.GuavaCollectors; import org.compiere.model.GridTabVO; +import com.fasterxml.jackson.annotation.JsonCreator; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -59,6 +60,7 @@ public static DetailId fromTabNoOrNull(final int tabNo) return new DetailId(tabNo); } + @JsonCreator public static final DetailId fromJson(String json) { if (json == null) @@ -93,7 +95,7 @@ public static final Set toJson(final Collection detailIds) return ImmutableSet.of(); } - return detailIds.stream().map(DetailId::toJson).collect(GuavaCollectors.toImmutableSet()); + return detailIds.stream().map(detailId -> detailId.toJson()).collect(GuavaCollectors.toImmutableSet()); } public static int getTabNo(final DetailId detailId) @@ -127,6 +129,12 @@ public String toString() return toJson(this); } + @JsonCreator + public String toJson() + { + return toJson(this); + } + @Override public int hashCode() {