From 4333164a37dcf4c6754ef00beb45bb0c97234079 Mon Sep 17 00:00:00 2001 From: unaibrrgn <75972112+unaibrrgn@users.noreply.github.com> Date: Tue, 9 Aug 2022 14:22:37 +0200 Subject: [PATCH] Added status parameter to API search #138 Added new status parameter to API item searches. --- .../base/utility/ItemproposedHelper.java | 20 ++++- .../crudimplementation/RegItemManager.java | 15 ++++ .../RegItemproposedManager.java | 16 ++++ .../constants/SQLConstants.java | 4 +- .../re3gistry2/javaapi/cache/model/Item.java | 10 +++ .../javaapi/cache/supplier/ItemSupplier.java | 53 +++++++++++- .../cache/supplier/ItemproposedSupplier.java | 44 +++++++++- .../ec/re3gistry2/restapi/ItemsServlet.java | 82 ++++++++++++++++++- 8 files changed, 233 insertions(+), 11 deletions(-) diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/ItemproposedHelper.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/ItemproposedHelper.java index f4940b81..96adbac0 100644 --- a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/ItemproposedHelper.java +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/ItemproposedHelper.java @@ -55,10 +55,17 @@ public static String getProposedURI(RegItemproposed regItemproposed, RegItem reg // Creating the full URI String uri = regItemproposed.getLocalid(); - // URI for external items - if (regItemproposed.getExternal()) { + if (regItemproposed.getExternal() != null) { + if (regItemproposed.getExternal()) { return uri; } + }else{ + + } + // URI for external items +// if (regItemproposed.getExternal()) { +// return uri; +// } List regRelationproposeds = regRelationproposedManager.getAll(regItemproposed, regRelationpredicateCollection); List regRelations = null; @@ -84,7 +91,16 @@ public static String getProposedURI(RegItemproposed regItemproposed, RegItem reg switch (regItemproposed.getRegItemclass().getRegItemclasstype().getLocalid()) { case BaseConstants.KEY_ITEMCLASS_TYPE_ITEM: + +// NOT VALID : TEST APPROACH +// if(regItemRegister.getRegItemclass().getBaseuri() == null){ +// uri = regItemRegister.getRegItemclass().getRegItemclassParent().getBaseuri() + "/" + regItemRegister.getRegItemclass().getRegItemclassParent().getLocalid() + "/" + uri; +// }else{ +// uri = regItemRegister.getRegItemclass().getBaseuri() + "/" + regItemRegister.getLocalid() + "/" + uri; +// } + uri = regItemRegister.getRegItemclass().getBaseuri() + "/" + regItemRegister.getLocalid() + "/" + uri; + break; case BaseConstants.KEY_ITEMCLASS_TYPE_REGISTER: uri = regItemproposed.getRegItemclass().getBaseuri() + "/" + uri; diff --git a/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegItemManager.java b/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegItemManager.java index 02b32324..359cdc8d 100644 --- a/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegItemManager.java +++ b/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegItemManager.java @@ -202,6 +202,21 @@ public RegItem getByLocalidAndRegItemClass(String localid, RegItemclass regItemc return (RegItem) q.getSingleResult(); } + + public RegItem getByLocalidAndRegItemClassAndRegStatus(String localid, RegItemclass regItemclass, RegStatus regStatus) throws Exception { + //Checking parameters + if (localid == null || regItemclass == null) { + throw new Exception(MessageFormat.format(ErrorConstants.ERROR_MANAGER_PATTERN_NULL, "uuid")); + } + + //Preparing query + Query q = this.em.createQuery(SQLConstants.SQL_GET_REGITEM_BY_LOCALID_REGITEMCLASS_REGSTATUS); + q.setParameter(SQLConstants.SQL_PARAMETERS_LOCALID, localid); + q.setParameter(SQLConstants.SQL_PARAMETERS_REGITEMCLASS, regItemclass); + q.setParameter(SQLConstants.SQL_PARAMETERS_REGSTATUS, regStatus); + + return (RegItem) q.getSingleResult(); + } /** * Returns all the RegItems by RegItemType diff --git a/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegItemproposedManager.java b/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegItemproposedManager.java index a426c2dd..db16bb30 100644 --- a/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegItemproposedManager.java +++ b/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegItemproposedManager.java @@ -184,6 +184,22 @@ public RegItemproposed getByLocalidAndRegItemClass(String localid, RegItemclass return (RegItemproposed) q.getSingleResult(); } + + public RegItemproposed getByLocalidAndRegItemClassAndRegStatus(String localid, RegItemclass regItemclass, RegStatus regStatus) throws Exception { + //Checking parameters + if (localid == null || regItemclass == null) { + throw new Exception(MessageFormat.format(ErrorConstants.ERROR_MANAGER_PATTERN_NULL, "uuid")); + } + + //Preparing query + Query q = this.em.createQuery(SQLConstants.SQL_GET_REGITEMPROPOSED_BY_LOCALID_REGITEMCLASS_REGSTATUS); + //Query q = this.em.createQuery(SQLConstants.SQL_GET_REGITEMPROPOSED_BY_LOCALID_REGITEMCLASS); + q.setParameter(SQLConstants.SQL_PARAMETERS_LOCALID, localid); + q.setParameter(SQLConstants.SQL_PARAMETERS_REGITEMCLASS, regItemclass); + q.setParameter(SQLConstants.SQL_PARAMETERS_REGSTATUS, regStatus); + + return (RegItemproposed) q.getSingleResult(); + } /** * Returns all the RegItemproposeds by RegItemType diff --git a/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/constants/SQLConstants.java b/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/constants/SQLConstants.java index 7838057d..51ee1077 100644 --- a/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/constants/SQLConstants.java +++ b/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/constants/SQLConstants.java @@ -59,6 +59,7 @@ private SQLConstants() { // RegItem public static final String SQL_GET_REGITEM_BY_LOCALID = "SELECT r FROM RegItem r WHERE r.localid = :localid"; public static final String SQL_GET_REGITEM_BY_LOCALID_REGITEMCLASS = "SELECT r FROM RegItem r WHERE r.localid = :localid AND r.regItemclass = :regItemclass"; + public static final String SQL_GET_REGITEM_BY_LOCALID_REGITEMCLASS_REGSTATUS = "SELECT r FROM RegItem r WHERE r.localid = :localid AND r.regItemclass = :regItemclass AND r.regStatus = :regStatus"; public static final String SQL_GET_REGITEM_BY_REGITEMCLASSTYPE = "SELECT r FROM RegItem r JOIN r.regItemclass i WHERE i.regItemclasstype = :regItemclasstype"; public static final String SQL_GET_REGITEM_BY_REGITEMCLASSTYPE_ACTIVE = "SELECT r FROM RegItem r JOIN r.regItemclass i WHERE i.regItemclasstype = :regItemclasstype AND i.active = TRUE"; public static final String SQL_GET_REGITEM_BY_REGITEMCLASS = "SELECT r FROM RegItem r WHERE r.regItemclass = :regItemclass"; @@ -83,6 +84,7 @@ private SQLConstants() { // RegItemproposed public static final String SQL_GET_REGITEMPROPOSED_BY_LOCALID_REGITEMCLASS = "SELECT r FROM RegItemproposed r WHERE r.localid = :localid AND r.regItemclass = :regItemclass"; + public static final String SQL_GET_REGITEMPROPOSED_BY_LOCALID_REGITEMCLASS_REGSTATUS = "SELECT r FROM RegItemproposed r WHERE r.localid = :localid AND r.regItemclass = :regItemclass AND r.regStatus = :regStatus"; public static final String SQL_GET_REGITEMPROPOSED_BY_REGITEMCLASSTYPE = "SELECT r FROM RegItemproposed r JOIN r.regItemclass i WHERE i.regItemclasstype = :regItemclasstype"; public static final String SQL_GET_REGITEMPROPOSED_BY_REGITEMCLASS = "SELECT r FROM RegItemproposed r WHERE r.regItemclass = :regItemclass"; public static final String SQL_GET_REGITEMPROPOSED_BY_REGITEMCLASSES = "SELECT r FROM RegItemproposed r WHERE r.regItemclass IN :regItemclasses ORDER BY r.localid"; @@ -223,5 +225,5 @@ private SQLConstants() { // RegStatus public static final String SQL_GET_REGSTATUS_BY_REGSTATUSGROUP = "SELECT r FROM RegStatus r WHERE r.regStatusgroup = :regStatusgroup"; public static final String SQL_GET_REGSTATUSPUBIC_BY_REGSTATUSGROUP = "SELECT r FROM RegStatus r WHERE r.regStatusgroup = :regStatusgroup AND r.ispublic = TRUE"; - + } diff --git a/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/cache/model/Item.java b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/cache/model/Item.java index 8b7378ed..96d4a888 100644 --- a/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/cache/model/Item.java +++ b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/cache/model/Item.java @@ -29,6 +29,7 @@ import java.util.List; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import eu.europa.ec.re3gistry2.model.RegLanguagecode; import java.io.Serializable; /** @@ -55,6 +56,7 @@ public class Item extends ContainedItem implements Serializable { private ItemRef registry; private ItemRef register; private List containedItems; + private List activeLanguages; public ItemRef getRegistry() { return registry; @@ -79,5 +81,13 @@ public List getContainedItems() { public void setContainedItems(List containedItems) { this.containedItems = containedItems; } + + public List getActiveLanguages() { + return activeLanguages; + } + + public void setActiveLanguages(List activeLanguages) { + this.activeLanguages = activeLanguages; + } } diff --git a/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/cache/supplier/ItemSupplier.java b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/cache/supplier/ItemSupplier.java index 26ca661f..8120bfa4 100644 --- a/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/cache/supplier/ItemSupplier.java +++ b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/cache/supplier/ItemSupplier.java @@ -48,6 +48,7 @@ import eu.europa.ec.re3gistry2.crudimplementation.RegItemclassManager; import eu.europa.ec.re3gistry2.crudimplementation.RegItemhistoryManager; import eu.europa.ec.re3gistry2.crudimplementation.RegItemproposedManager; +import eu.europa.ec.re3gistry2.crudimplementation.RegLanguagecodeManager; import eu.europa.ec.re3gistry2.crudimplementation.RegLocalizationManager; import eu.europa.ec.re3gistry2.crudimplementation.RegLocalizationproposedManager; import eu.europa.ec.re3gistry2.crudimplementation.RegRelationManager; @@ -109,6 +110,7 @@ public class ItemSupplier { private final RegRelationproposedManager regRelationproposedManager; private final RegLocalizationproposedManager reglocalizationproposedManager; private final ItemproposedSupplier itemproposedSupplier; + private final RegLanguagecodeManager regLanguagecodeManager; private final RegLanguagecode masterLanguage; private final RegLanguagecode languageCode; @@ -146,7 +148,8 @@ public ItemSupplier(EntityManager em, this.regRelationproposedManager = new RegRelationproposedManager(em); this.itemproposedSupplier = new ItemproposedSupplier(em, masterLanguage, languageCode); this.reglocalizationproposedManager = new RegLocalizationproposedManager(em); - + this.regLanguagecodeManager = new RegLanguagecodeManager(em); + this.masterLanguage = masterLanguage; this.languageCode = languageCode; @@ -176,6 +179,15 @@ public Item getItemByUri(String uri) throws Exception { } return toItem(item); } + + public Item getItemByUriAndStatus(String uri, String status) throws Exception { + RegItem item = getRegItemByUriAndStatus(uri, status); + if (item == null) { + return null; + } + return toItem(item); + } + private RegItem getRegItemByUri(String uri) throws Exception { int i = uri.lastIndexOf('/'); @@ -202,6 +214,39 @@ private RegItem getRegItemByUri(String uri) throws Exception { } return null; } + + private RegItem getRegItemByUriAndStatus(String uri, String itemStatus) throws Exception { + int i = uri.lastIndexOf('/'); + if (i < 0) { + throw new NoResultException(); + } + String localid = uri.substring(i + 1); + try { + int uriCollection = uri.substring(0, i).lastIndexOf('/'); + String regItemClassLocalId = uri.substring(uriCollection + 1).replace("/" + localid, ""); + RegItemclass parentClass = regItemClassManager.get(regItemClassLocalId); + RegItemclass regItemRegItemClass = regItemClassManager.getChildItemclass(parentClass).get(0); + + RegStatus status = regStatusManager.findByLocalid(itemStatus); + RegItem regItem; + if(status.getIspublic()){ + regItem = regItemManager.getByLocalidAndRegItemClassAndRegStatus(localid, regItemRegItemClass, status); + }else{ + return null; + } + + if (uri.equals(ItemHelper.getURI(regItem))) { + return regItem; + } + } catch (Exception e) { + for (RegItem item : regItemManager.getByLocalid(localid)) { + if (uri.equals(ItemHelper.getURI(item))) { + return item; + } + } + } + return null; + } private Item toItem(RegItem regItem) throws Exception { if (!regItem.getRegStatus().getIspublic()) { @@ -222,6 +267,7 @@ private Item toItem(RegItem regItem) throws Exception { setNarrowerFromRegItem(regItem, item); setBroaderFromRegItem(regItem, item); +// setActiveLangList(item); return item; } @@ -1217,4 +1263,9 @@ private String getLabelfromItem(RegItem regitem) throws Exception { return loc.getValue(); } + + private void setActiveLangList(Item item) throws Exception{ + List activeLanguages = regLanguagecodeManager.getAllActive(); + item.setActiveLanguages(activeLanguages); + } } diff --git a/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/cache/supplier/ItemproposedSupplier.java b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/cache/supplier/ItemproposedSupplier.java index 6e54d9cc..ca03f4eb 100644 --- a/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/cache/supplier/ItemproposedSupplier.java +++ b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/cache/supplier/ItemproposedSupplier.java @@ -164,7 +164,7 @@ public Item getItemProposedByUuid(String uuid) throws Exception { //RegItem finalItem = new RegItem(itemProposed.getUuid(), itemProposed.getLocalid(), itemProposed.getInsertdate()); return toItemProposed(itemProposed); } - + public Item getItemProposedByUri(String uri) throws Exception { RegItemproposed item = getRegItemProposedByUri(uri); if (item == null) { @@ -173,6 +173,14 @@ public Item getItemProposedByUri(String uri) throws Exception { return toItemProposed(item); } + public Item getItemProposedByUriAndStatus(String uri, String itemStatus) throws Exception { + RegItemproposed item = getRegItemProposedByUriAndStatus(uri, itemStatus); + if (item == null) { + return null; + } + return toItemProposed(item); + } + private RegItemproposed getRegItemProposedByUri(String uri) throws Exception { int i = uri.lastIndexOf('/'); if (i < 0) { @@ -184,8 +192,34 @@ private RegItemproposed getRegItemProposedByUri(String uri) throws Exception { String regItemClassLocalId = uri.substring(uriCollection + 1).replace("/" + localid, ""); RegItemclass parentClass = regItemClassManager.getByLocalid(regItemClassLocalId); RegItemclass regItemRegItemClass = regItemClassManager.getChildItemclass(parentClass).get(0); + RegItemproposed regItemproposed = regItemproposedManager.getByLocalidAndRegItemClass(localid, regItemRegItemClass); - RegItemproposed regItemproposed = regItemproposedManager.getByLocalidAndRegItemClass(localid, regItemRegItemClass); + return regItemproposed; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + private RegItemproposed getRegItemProposedByUriAndStatus(String uri, String itemStatus) throws Exception { + int i = uri.lastIndexOf('/'); + if (i < 0) { + throw new NoResultException(); + } + String localid = uri.substring(i + 1); + try { + int uriCollection = uri.substring(0, i).lastIndexOf('/'); + String regItemClassLocalId = uri.substring(uriCollection + 1).replace("/" + localid, ""); + RegItemclass parentClass = regItemClassManager.getByLocalid(regItemClassLocalId); + RegItemclass regItemRegItemClass = regItemClassManager.getChildItemclass(parentClass).get(0); + + RegStatus status = regStatusManager.findByLocalid(itemStatus); + RegItemproposed regItemproposed; + if(status.getIspublic()){ + regItemproposed = regItemproposedManager.getByLocalidAndRegItemClassAndRegStatus(localid, regItemRegItemClass, status); + }else{ + return null; + } return regItemproposed; } catch (Exception e) { @@ -193,6 +227,7 @@ private RegItemproposed getRegItemProposedByUri(String uri) throws Exception { return null; } } + private Item toItemProposed(RegItemproposed regItemproposed) throws Exception { boolean isPublic = regItemproposed.getRegStatus().getIspublic(); @@ -1013,9 +1048,12 @@ private ContainedItem setMainPropertiesForRegItemProposed(RegItemproposed regIte if (isParentList != null && !isParentList.isEmpty()) { item.setIsParent(true); } - if (regItemproposed.getExternal()) { + if(regItemproposed.getExternal() != null){ + if (regItemproposed.getExternal()) { item.setExternal(true); + } } + } return item; diff --git a/sources/Re3gistry2RestAPI/src/main/java/eu/europa/ec/re3gistry2/restapi/ItemsServlet.java b/sources/Re3gistry2RestAPI/src/main/java/eu/europa/ec/re3gistry2/restapi/ItemsServlet.java index 39ef1561..cbd4fd5d 100644 --- a/sources/Re3gistry2RestAPI/src/main/java/eu/europa/ec/re3gistry2/restapi/ItemsServlet.java +++ b/sources/Re3gistry2RestAPI/src/main/java/eu/europa/ec/re3gistry2/restapi/ItemsServlet.java @@ -61,6 +61,10 @@ import eu.europa.ec.re3gistry2.javaapi.cache.util.NoVersionException; import eu.europa.ec.re3gistry2.restapi.util.RequestUtil; import eu.europa.ec.re3gistry2.restapi.util.ResponseUtil; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; public class ItemsServlet extends HttpServlet { @@ -103,11 +107,45 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) String uuid = RequestUtil.getParamTrimmed(req, "uuid", null); String uri = RequestUtil.getParamTrimmed(req, "uri", null); String format = RequestUtil.getParamTrimmed(req, "format", null); + String status=RequestUtil.getParamTrimmed(req, "status", null); uri = removeTrailingSlashes(uri); Predicate typeFilter = getTypeFilter(path); Formatter formatter = formatters.get(format); + if(lang.equalsIgnoreCase("active")){ + String type = "application/json"; + EntityManager em = emf.createEntityManager(); + RegLanguagecodeManager regLanguagecodeManager = new RegLanguagecodeManager(em); + List activeLanguages = null; + try { + activeLanguages = regLanguagecodeManager.getAllActive(); + } catch (Exception ex) { + java.util.logging.Logger.getLogger(ItemsServlet.class.getName()).log(Level.SEVERE, null, ex); + } + + //TOITEM + List > toActiveLanguages = new ArrayList(); + for(int i=0; i language = new HashMap<>(); + language.put("uuid", activeLanguages.get(i).getUuid()); + language.put("label", activeLanguages.get(i).getLabel()); + language.put("iso6391code", activeLanguages.get(i).getIso6391code()); + language.put("iso6392code", activeLanguages.get(i).getIso6392code()); + language.put("masterlanguage", activeLanguages.get(i).getMasterlanguage().toString()); + language.put("active", activeLanguages.get(i).getActive().toString()); + toActiveLanguages.add(language); + } + + byte[] body = JSONInternalFormatter.OM.writeValueAsBytes(toActiveLanguages); + resp.setContentType(type); + resp.setContentLength(body.length); + try (OutputStream out = resp.getOutputStream()) { + out.write(body); + } + return; + } + if (typeFilter == null) { ResponseUtil.err(resp, ApiError.NOT_FOUND); return; @@ -154,10 +192,23 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) //if the item contains no version reference in the URL or if the item contains :0 if (version == 0) { - optItem = getItemByUri(uri.replace(":" + version, ""), lang, itemSupplier); - if (!optItem.isPresent()) { - optItem = getItemProposedByUri(uri, lang, itemproposedSupplier); + if(status!=null){ + try{ + optItem = getItemProposedByUriAndStatus(uri, status, itemproposedSupplier); + }catch(Exception e){ + optItem = getItemByUriAndStatus(uri.replace(":" + version, ""), lang, itemSupplier, status); + } + }else{ + optItem = getItemByUri(uri.replace(":" + version, ""), lang, itemSupplier); + + //Check if optItem has a value, if it doesn't --> search the item in the proposed table + if(!optItem.isPresent()){ + optItem = getItemProposedByUri(uri, itemproposedSupplier); + } } + +// if (!optItem.isPresent()) { +// } } else { int sizeHistory = itemHistorySupplier.sizeItemInHistory(uri); if (sizeHistory == 0 || sizeHistory + 1 == version) { @@ -309,13 +360,21 @@ private Optional getItemProposedByUuid(String uuid, String language, Itemp return Optional.of(item); } - private Optional getItemProposedByUri(String uri, String language, ItemproposedSupplier itemproposedSupplier) throws Exception { + private Optional getItemProposedByUri(String uri, ItemproposedSupplier itemproposedSupplier) throws Exception { Item item = itemproposedSupplier.getItemProposedByUri(uri); if (item == null) { return Optional.empty(); } return Optional.of(item); } + + private Optional getItemProposedByUriAndStatus(String uri, String itemStatus, ItemproposedSupplier itemproposedSupplier) throws Exception { + Item item = itemproposedSupplier.getItemProposedByUriAndStatus(uri, itemStatus); + if (item == null) { + return Optional.empty(); + } + return Optional.of(item); + } private Optional getItemByUri(String uri, String language, ItemSupplier itemSupplier) throws Exception { Item cached = cache.getByUrl(language, uri, null); @@ -331,6 +390,21 @@ private Optional getItemByUri(String uri, String language, ItemSupplier it cache.add(language, item, null); return Optional.of(item); } + + private Optional getItemByUriAndStatus(String uri, String language, ItemSupplier itemSupplier, String itemStatus) throws Exception { + Item cached = cache.getByUrl(language, uri, null); + if (cached != null) { + return Optional.of(cached); + } + + Item item = itemSupplier.getItemByUriAndStatus(uri, itemStatus); + if (item == null) { + return Optional.empty(); + } + + cache.add(language, item, null); + return Optional.of(item); + } private Optional getItemHistoryByUuid(String uuid, String language, ItemHistorySupplier itemHistorySupplier) throws Exception { Item cached = cache.getByUuid(language, uuid);