Skip to content

Commit

Permalink
/window/{windowId}/{documentId}/{tabId}/{rowId}/references endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed May 26, 2017
1 parent c85864e commit 3a1c453
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent;
import de.metas.ui.web.window.datatypes.json.JSONDocumentLayout;
import de.metas.ui.web.window.datatypes.json.JSONDocumentPath;
import de.metas.ui.web.window.datatypes.json.JSONDocumentReference;
import de.metas.ui.web.window.datatypes.json.JSONDocumentReferencesGroup;
import de.metas.ui.web.window.datatypes.json.JSONDocumentReferencesGroupList;
import de.metas.ui.web.window.datatypes.json.JSONLookupValuesList;
import de.metas.ui.web.window.datatypes.json.JSONOptions;
Expand Down Expand Up @@ -396,7 +398,7 @@ public JSONLookupValuesList getDocumentFieldTypeahead(
final DocumentPath documentPath = DocumentPath.rootDocumentPath(windowId, documentId);
return getDocumentFieldTypeahead(documentPath, fieldName, query);
}

/**
* Typeahead for included document's field
*/
Expand All @@ -414,7 +416,7 @@ public JSONLookupValuesList getDocumentFieldTypeahead(
final DocumentPath documentPath = DocumentPath.includedDocumentPath(windowId, documentId, tabId, rowId);
return getDocumentFieldTypeahead(documentPath, fieldName, query);
}

/** Typeahead: unified implementation */
private JSONLookupValuesList getDocumentFieldTypeahead(final DocumentPath documentPath, final String fieldName, final String query)
{
Expand All @@ -436,7 +438,7 @@ public JSONLookupValuesList getDocumentFieldDropdown(
final DocumentPath documentPath = DocumentPath.rootDocumentPath(windowId, documentId);
return getDocumentFieldDropdown(documentPath, fieldName);
}

@GetMapping("/{windowId}/{documentId}/{tabId}/{rowId}/field/{fieldName}/dropdown")
public JSONLookupValuesList getDocumentFieldDropdown(
@PathVariable("windowId") final String windowIdStr //
Expand All @@ -450,7 +452,7 @@ public JSONLookupValuesList getDocumentFieldDropdown(
final DocumentPath documentPath = DocumentPath.includedDocumentPath(windowId, documentId, tabId, rowId);
return getDocumentFieldDropdown(documentPath, fieldName);
}

private JSONLookupValuesList getDocumentFieldDropdown(final DocumentPath documentPath, final String fieldName)
{
userSession.assertLoggedIn();
Expand All @@ -472,7 +474,7 @@ public JSONZoomInto getDocumentFieldZoomInto(
final DocumentPath documentPath = DocumentPath.rootDocumentPath(windowId, documentId);
return getDocumentFieldZoomInto(documentPath, fieldName);
}

@ApiOperation("field current value's window layout to zoom into")
@GetMapping("/{windowId}/{documentId}/{tabId}/{rowId}/field/{fieldName}/zoomInto")
public JSONZoomInto getDocumentFieldZoomInto(
Expand All @@ -487,7 +489,7 @@ public JSONZoomInto getDocumentFieldZoomInto(
final DocumentPath documentPath = DocumentPath.includedDocumentPath(windowId, documentId, tabId, rowId);
return getDocumentFieldZoomInto(documentPath, fieldName);
}

private JSONZoomInto getDocumentFieldZoomInto(final DocumentPath documentPath, final String fieldName)
{
userSession.assertLoggedIn();
Expand Down Expand Up @@ -569,6 +571,27 @@ public JSONDocumentActionsList getDocumentActions(
});
}

@GetMapping(value = "/{windowId}/{documentId}/{tabId}/{rowId}/references")
public JSONDocumentReferencesGroup getDocumentReferences(
@PathVariable("windowId") final String windowIdStr,
@PathVariable("documentId") final String documentIdStr,
@PathVariable("tabId") final String tabIdStr,
@PathVariable("rowId") final String rowIdStr)
{
userSession.assertLoggedIn();

// Get document references
final WindowId windowId = WindowId.fromJson(windowIdStr);
final DocumentPath documentPath = DocumentPath.includedDocumentPath(windowId, documentIdStr, tabIdStr, rowIdStr);
final List<DocumentReference> documentReferences = documentReferencesService.getDocumentReferences(documentPath);

final JSONOptions jsonOpts = newJSONOptions().build();
return JSONDocumentReferencesGroup.builder()
.caption("References")
.references(JSONDocumentReference.ofList(documentReferences, jsonOpts))
.build();
}

@GetMapping(value = "/{windowId}/{documentId}/references")
public JSONDocumentReferencesGroupList getDocumentReferences(
@PathVariable("windowId") final String windowIdStr //
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package de.metas.ui.web.window.datatypes.json;

import java.util.Collection;
import java.util.List;

import org.slf4j.Logger;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;

import de.metas.logging.LogManager;
import de.metas.ui.web.document.filter.DocumentFilter;
Expand All @@ -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
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/
Expand All @@ -50,6 +54,19 @@ static final JSONDocumentReference of(final DocumentReference documentReference,
}
}

public static final List<JSONDocumentReference> ofList(final Collection<DocumentReference> documentReferences, final JSONOptions jsonOpts)
{
if (documentReferences.isEmpty())
{
return ImmutableList.of();
}

return documentReferences.stream()
.map(documentReference -> of(documentReference, jsonOpts))
.filter(jsonDocumentReference -> jsonDocumentReference != null)
.collect(ImmutableList.toImmutableList());
}

private static final transient Logger logger = LogManager.getLogger(JSONDocumentReference.class);

@JsonProperty("id")
Expand Down

0 comments on commit 3a1c453

Please sign in to comment.