Skip to content

Commit

Permalink
Added status parameter to API search #138
Browse files Browse the repository at this point in the history
Added new status parameter to API item searches.
  • Loading branch information
unaibrrgn committed Aug 9, 2022
1 parent 277423e commit 4333164
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<RegRelationproposed> regRelationproposeds = regRelationproposedManager.getAll(regItemproposed, regRelationpredicateCollection);
List<RegRelation> regRelations = null;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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";

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -55,6 +56,7 @@ public class Item extends ContainedItem implements Serializable {
private ItemRef registry;
private ItemRef register;
private List<ContainedItem> containedItems;
private List<RegLanguagecode> activeLanguages;

public ItemRef getRegistry() {
return registry;
Expand All @@ -79,5 +81,13 @@ public List<ContainedItem> getContainedItems() {
public void setContainedItems(List<ContainedItem> containedItems) {
this.containedItems = containedItems;
}

public List<RegLanguagecode> getActiveLanguages() {
return activeLanguages;
}

public void setActiveLanguages(List<RegLanguagecode> activeLanguages) {
this.activeLanguages = activeLanguages;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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('/');
Expand All @@ -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()) {
Expand All @@ -222,6 +267,7 @@ private Item toItem(RegItem regItem) throws Exception {
setNarrowerFromRegItem(regItem, item);
setBroaderFromRegItem(regItem, item);

// setActiveLangList(item);
return item;
}

Expand Down Expand Up @@ -1217,4 +1263,9 @@ private String getLabelfromItem(RegItem regitem) throws Exception {

return loc.getValue();
}

private void setActiveLangList(Item item) throws Exception{
List<RegLanguagecode> activeLanguages = regLanguagecodeManager.getAllActive();
item.setActiveLanguages(activeLanguages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -184,15 +192,42 @@ 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) {
e.printStackTrace();
return null;
}
}


private Item toItemProposed(RegItemproposed regItemproposed) throws Exception {
boolean isPublic = regItemproposed.getRegStatus().getIspublic();
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 4333164

Please sign in to comment.