Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public class ItemDomainLogbookController extends ItemController<ItemDomainLogboo
LogReactionFacade logReactionFacade;

private EntityType currentEntityType = null;
private boolean fullListMode = false;
private Log lastLog;

private List<SearchResult> logResults;
Expand Down Expand Up @@ -144,6 +145,11 @@ public class ItemDomainLogbookController extends ItemController<ItemDomainLogboo

private static final String OPS_ENTITY_TYPE_NAME = "ops";

// Entity type url parameter requesting every logbook type.
private static final int FULL_LIST_ET_ID = -1;
private static final String FULL_LIST_URL = "fullList";
private static final String FULL_LIST_PAGE_TITLE = "All Log Documents";

private static final String LOGBOOK_SETTINGS_SHOW_TIMESTAMP_KEY = LogDocumentSettings.showTimestampKey.getValue();
private static final String LOGBOOK_SETTINGS_TEMPLATE_LOG_MODE_KEY = LogDocumentSettings.logTemplateModeKey.getValue();
private static final String LOGBOOK_SETTINGS_TEMPLATE_LOG_MODE_NONE_VAL = LogDocumentSettings.logTemplateModeNoneVal.getValue();
Expand Down Expand Up @@ -779,6 +785,7 @@ public void processViewRequestParams() {
}

public void processPreRenderOPSList() {
fullListMode = false;
if (currentEntityType != null && itemLazyDataModel != null) {
String name = currentEntityType.getName();
if (name.equals(OPS_ENTITY_TYPE_NAME)) {
Expand Down Expand Up @@ -839,12 +846,21 @@ private String getListRedirectForEntityType(EntityType entityType, boolean inclu
public void processPreRenderList() {
super.processPreRenderList();

fullListMode = false;

EntityType lastEntityType = currentEntityType;
String currentEntityTypeIdStr = SessionUtility.getRequestParameterValue("et");

if (currentEntityTypeIdStr != null) {
// Load up entityTypeId that was specified.
int etId = Integer.parseInt(currentEntityTypeIdStr);

if (etId == FULL_LIST_ET_ID) {
// Request for log documents of every logbook type.
redirectToFullList();
return;
}

EntityType et = entityTypeFacade.find(etId);
redirectToEntityTypeList(et);
return;
Expand Down Expand Up @@ -881,7 +897,34 @@ public void processPreRenderList() {

@Override
public void processPreRenderTemplateList() {
fullListMode = false;
super.processPreRenderList();
}

// Calls super.processPreRenderList() to skip this class' redirect to a single type list.
public void processPreRenderFullList() {
super.processPreRenderList();

fullListMode = true;
currentEntityType = null;

ItemDomainLogbookLazyDataModel dataModel = getItemLazyDataModel();
dataModel.setAllLogbookTypes();
dataModel.refreshDataModel();
}

private void redirectToFullList() {
String redirect = String.format("%s/%s", getDomainPath(), FULL_LIST_URL);
try {
SessionUtility.redirectTo(redirect);
} catch (IOException ex) {
logger.error(ex);
SessionUtility.addErrorMessage("Error", ex.getMessage());
}
}

public boolean isFullListMode() {
return fullListMode;
}

@Override
Expand Down Expand Up @@ -976,6 +1019,10 @@ public boolean isDisplayRowExpansionAssembly(Item item) {
public String getItemListPageTitle() {
String itemListPageTitle = super.getItemListPageTitle();

if (fullListMode) {
return FULL_LIST_PAGE_TITLE;
}

if (currentEntityType != null) {
String displayName = currentEntityType.getLongDisplayName();;

Expand All @@ -989,6 +1036,11 @@ public String getItemListPageTitle() {
}

public void navigateToLogDocumentList() {
if (fullListMode) {
redirectToFullList();
return;
}

EntityType entityType = getCurrent().getEntityTypeList().get(0);

redirectToEntityTypeList(entityType);
Expand All @@ -1000,8 +1052,12 @@ public ItemDomainLogbook getNextLogDocument() {
boolean nextDocLoaded = currentDoc.getNextDocLoaded();
if (!nextDocLoaded) {
Integer logId = currentDoc.getId();
String entityTypeName = currentDoc.getEntityTypeList().get(0).getName();
nextDoc = itemDomainLogbookFacade.getNextLogDocument(entityTypeName, logId);
if (fullListMode) {
nextDoc = itemDomainLogbookFacade.getNextLogDocument(logId);
} else {
String entityTypeName = currentDoc.getEntityTypeList().get(0).getName();
nextDoc = itemDomainLogbookFacade.getNextLogDocument(entityTypeName, logId);
}
currentDoc.setNextDoc(nextDoc);
currentDoc.setNextDocLoaded(true);
} else {
Expand All @@ -1016,8 +1072,12 @@ public ItemDomainLogbook getPrevLogDocument() {
boolean prevDocLoaded = currentDoc.getPrevDocLoaded();
if (!prevDocLoaded) {
Integer logId = currentDoc.getId();
String entityTypeName = currentDoc.getEntityTypeList().get(0).getName();
prevDoc = itemDomainLogbookFacade.getPreviousLogDocument(entityTypeName, logId);
if (fullListMode) {
prevDoc = itemDomainLogbookFacade.getPreviousLogDocument(logId);
} else {
String entityTypeName = currentDoc.getEntityTypeList().get(0).getName();
prevDoc = itemDomainLogbookFacade.getPreviousLogDocument(entityTypeName, logId);
}
currentDoc.setPrevDoc(prevDoc);
currentDoc.setPrevDocLoaded(true);
} else {
Expand Down Expand Up @@ -1519,6 +1579,11 @@ private void updateLogbookSettingDefaultValue(SettingTypeControllerUtility stcu,

// </editor-fold>
public final String getCurrentListPermalink() {
if (fullListMode) {
String redirect = String.format("%s/list?et=%d", getDomainPath(), FULL_LIST_ET_ID);
return String.format("%s%s", contextRootPermanentUrl, redirect);
}

if (currentEntityType != null) {
String redirect = getListRedirectForEntityType(currentEntityType, true, true);
String viewPath = String.format("%s%s", contextRootPermanentUrl, redirect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
public class ItemDomainLogbookLazyDataModel extends ItemLazyDataModel<ItemDomainLogbookFacade, ItemDomainLogbookQueryBuilder> {

private boolean allLogbookTypes = false;

public ItemDomainLogbookLazyDataModel(ItemDomainLogbookFacade facade, Domain itemDomain, ItemSettings settings) {
super(facade, itemDomain, settings);

Expand All @@ -39,10 +41,24 @@ private void addDefaultSortOrder() {

@Override
protected ItemDomainLogbookQueryBuilder getQueryBuilder(Map filterMap, String sortField, SortOrder sortOrder) {
return new ItemDomainLogbookQueryBuilder(itemDomain.getId(), filterMap, sortField, sortOrder, settings);
return new ItemDomainLogbookQueryBuilder(itemDomain.getId(), filterMap, sortField, sortOrder, settings, allLogbookTypes);
}

// Show log documents of every logbook type instead of a single type.
public void setAllLogbookTypes() {
allLogbookTypes = true;
setCurrentEntityType(null);
}

public boolean isAllLogbookTypes() {
return allLogbookTypes;
}

public void setCurrentEntityType(String entityType) {
if (entityType != null) {
allLogbookTypes = false;
}

if (entityType == null) {
setDefaultFilterBy(null);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package gov.anl.aps.logr.portal.model.db.beans;

import gov.anl.aps.logr.portal.constants.EntityTypeName;
import gov.anl.aps.logr.portal.constants.ItemDomainName;
import gov.anl.aps.logr.portal.model.db.entities.ItemDomainLogbook;
import gov.anl.aps.logr.portal.utilities.SessionUtility;
Expand Down Expand Up @@ -57,6 +58,34 @@ public ItemDomainLogbook getNextLogDocument(String entityTypeName, Integer curre

}

// Previous top level log document across every logbook type, excluding templates.
public ItemDomainLogbook getPreviousLogDocument(Integer currentId) {
try {
return (ItemDomainLogbook) em.createNamedQuery("Item.findByDomainNameAndTopLevelBeforeId")
.setParameter("domainName", getDomain().getValue())
.setParameter("excludeEntityTypeName", EntityTypeName.template.getValue())
.setParameter("itemId", currentId)
.setMaxResults(1)
.getSingleResult();
} catch (NoResultException ex) {
}
return null;
}

// Next top level log document across every logbook type, excluding templates.
public ItemDomainLogbook getNextLogDocument(Integer currentId) {
try {
return (ItemDomainLogbook) em.createNamedQuery("Item.findByDomainNameAndTopLevelAfterId")
.setParameter("domainName", getDomain().getValue())
.setParameter("excludeEntityTypeName", EntityTypeName.template.getValue())
.setParameter("itemId", currentId)
.setMaxResults(1)
.getSingleResult();
} catch (NoResultException ex) {
}
return null;
}

public static ItemDomainLogbookFacade getInstance() {
return (ItemDomainLogbookFacade) SessionUtility.findFacade(ItemDomainLogbookFacade.class.getSimpleName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package gov.anl.aps.logr.portal.model.db.beans.builder;

import gov.anl.aps.logr.portal.constants.EntityTypeName;
import gov.anl.aps.logr.portal.controllers.settings.ItemSettings;
import java.util.Map;
import org.primefaces.model.SortOrder;
Expand All @@ -13,21 +14,34 @@
* @author djarosz
*/
public class ItemDomainLogbookQueryBuilder extends ItemQueryBuilder {


private final boolean allLogbookTypes;

public ItemDomainLogbookQueryBuilder(Integer domainId, Map filterMap, String sortField, SortOrder sortOrder, ItemSettings scopeSettings) {
this(domainId, filterMap, sortField, sortOrder, scopeSettings, false);
}

public ItemDomainLogbookQueryBuilder(Integer domainId, Map filterMap, String sortField, SortOrder sortOrder, ItemSettings scopeSettings, boolean allLogbookTypes) {
super(domainId, filterMap, sortField, sortOrder, scopeSettings);
}
this.allLogbookTypes = allLogbookTypes;
}

@Override
protected void generateWhereString() {
super.generateWhereString();

super.generateWhereString();

if (allLogbookTypes) {
// Top level log documents of every logbook type, excluding templates.
appendRawWhere("i.itemElementMemberList IS EMPTY");
appendRawWhere(ENTITY_TYPE_LIST_JOIN_NAME + ".name <> '" + EntityTypeName.template.getValue() + "'");
include_etl = true;
return;
}

if (filterMap == null || filterMap.isEmpty()) {
appendRawWhere("i.itemElementMemberList IS EMPTY");
appendRawWhere("i.entityTypeList IS EMPTY");
}
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class ItemQueryBuilder extends CdbQueryBuilder {
private static final String QUERY_STRING_START = "SELECT DISTINCT(i) FROM Item i ";
private static final String ITEM_ELEMENTS_LIST_JOIN_NAME = "fiel";
private static final String ITEM_PROJECT_LIST_JOIN_NAME = "ipl";
private static final String ENTITY_TYPE_LIST_JOIN_NAME = "etl";
protected static final String ENTITY_TYPE_LIST_JOIN_NAME = "etl";
private static final String ITEM_CATEGORY_LIST_JOIN_NAME = "icl";
private static final String ITEM_TYPE_LIST_JOIN_NAME = "itl";
private static final String ITEM_SOURCE_LIST_JOIN_NAME = "isl";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@
query = "SELECT DISTINCT(i) FROM Item i JOIN i.entityTypeList etl WHERE i.domain.name = :domainName and etl.name = :entityTypeName and i.itemElementMemberList IS EMPTY AND i.itemElementMemberList2 IS EMPTY AND i.id > :itemId ORDER BY i.id ASC"),
@NamedQuery(name = "Item.findByDomainNameAndEntityTypeAndTopLevelBeforeId",
query = "SELECT DISTINCT(i) FROM Item i JOIN i.entityTypeList etl WHERE i.domain.name = :domainName and etl.name = :entityTypeName and i.itemElementMemberList IS EMPTY AND i.itemElementMemberList2 IS EMPTY AND i.id < :itemId ORDER BY i.id DESC"),
@NamedQuery(name = "Item.findByDomainNameAndTopLevelAfterId",
query = "SELECT DISTINCT(i) FROM Item i JOIN i.entityTypeList etl WHERE i.domain.name = :domainName and etl.name <> :excludeEntityTypeName and i.itemElementMemberList IS EMPTY AND i.itemElementMemberList2 IS EMPTY AND i.id > :itemId ORDER BY i.id ASC"),
@NamedQuery(name = "Item.findByDomainNameAndTopLevelBeforeId",
query = "SELECT DISTINCT(i) FROM Item i JOIN i.entityTypeList etl WHERE i.domain.name = :domainName and etl.name <> :excludeEntityTypeName and i.itemElementMemberList IS EMPTY AND i.itemElementMemberList2 IS EMPTY AND i.id < :itemId ORDER BY i.id DESC"),
@NamedQuery(name = "Item.findByDomainNameAndEntityTypeAndTopLevelExcludeEntityType",
query = "SELECT DISTINCT(i) FROM Item i JOIN i.entityTypeList etl WHERE i.domain.name = :domainName and etl.name = :entityTypeName and (i.id not in (SELECT DISTINCT(i.id) FROM Item i JOIN i.entityTypeList etl WHERE i.domain.name = :domainName and etl.name = :excludeEntityTypeName)) and i.itemElementMemberList IS EMPTY AND i.itemElementMemberList2 IS EMPTY"),
@NamedQuery(name = "Item.findByDomainNameAndEntityTypeAndTopLevelOrderByDerivedFromItem",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private McpConstants() {
+ "once you know its id. All tools are read-only.";

public static final String PROP_ENABLED = "cdb.portal.mcp.enabled";
// Defaults to false by design: all MCP tools are read-only and the equivalent REST reads are unauthenticated too. Set true to require a valid token header.
public static final String PROP_REQUIRE_AUTH = "cdb.portal.mcp.requireAuth";
public static final String PROP_ALLOWED_ORIGINS = "cdb.portal.mcp.allowedOrigins";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
*/
package gov.anl.aps.logr.rest.mcp.tools;

import gov.anl.aps.logr.portal.constants.EntityTypeName;
import gov.anl.aps.logr.portal.constants.ItemDomainName;
import gov.anl.aps.logr.portal.model.db.beans.DomainFacade;
import gov.anl.aps.logr.portal.model.db.beans.ItemDomainLogbookFacade;
import gov.anl.aps.logr.portal.model.db.beans.ItemFacade;
import gov.anl.aps.logr.portal.model.db.beans.UserGroupFacade;
import gov.anl.aps.logr.portal.model.db.beans.UserInfoFacade;
import gov.anl.aps.logr.portal.model.db.entities.Domain;
import gov.anl.aps.logr.portal.model.db.entities.EntityType;
import gov.anl.aps.logr.portal.model.db.entities.ItemType;
import gov.anl.aps.logr.portal.model.db.entities.UserInfo;
import java.util.ArrayList;
import gov.anl.aps.logr.rest.utilities.LogbookDomainUtility;
import java.util.List;

/** Facade bundle plus the resolved current user, built once per MCP request and passed to every {@link McpTool#call}. */
Expand Down Expand Up @@ -63,20 +60,13 @@ public UserInfo getCurrentUser() {
return currentUser;
}

private Domain getLogbookDomain() {
return domainFacade.find(ItemDomainName.LOGBOOK_ID);
}

// Copies before filtering — SearchRoute/LogbookRoute's equivalent helper mutates the shared, JPA-managed list in place.
// Delegates to the shared helper so REST and MCP filter logbook types identically.
public List<EntityType> getLogbookTypes() {
Domain domain = getLogbookDomain();
List<EntityType> logbookTypes = new ArrayList<>(domain.getAllowedEntityTypeList());
logbookTypes.removeIf(t -> t.getName().equals(EntityTypeName.template.getValue()));
return logbookTypes;
return LogbookDomainUtility.getLogbookTypes(domainFacade);
}

// Delegates to the shared helper so REST and MCP resolve systems identically.
public List<ItemType> getLogbookSystems() {
Domain domain = getLogbookDomain();
return domain.getItemTypeList();
return LogbookDomainUtility.getLogbookSystems(domainFacade);
}
}
Loading
Loading