Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into eea-4.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
fxprunayre committed Apr 15, 2024
2 parents c12306d + 1867f2e commit f7b5bfe
Show file tree
Hide file tree
Showing 81 changed files with 806 additions and 770 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ public interface IMetadataStatus {
MetadataStatus setStatusExt(ServiceContext context, int id, int status, ISODate changeDate, String changeMessage) throws Exception;

/**
* Set status of metadata id and do not reindex metadata id afterwards.
* Set status of metadata id and reindex metadata id afterwards based on updateIndex flag
*
* @param status metadata status to set
* @param updateIndex index update flag
*
* @return the saved status entity object
*/
MetadataStatus setStatusExt(MetadataStatus status) throws Exception;
MetadataStatus setStatusExt(MetadataStatus status, boolean updateIndex) throws Exception;

/**
* Set status of metadata id and reindex metadata id afterwards.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ public MetadataStatus setStatus(ServiceContext context, int id, int status, ISOD
}

@Override
public MetadataStatus setStatusExt(MetadataStatus metatatStatus) throws Exception {
public MetadataStatus setStatusExt(MetadataStatus metatatStatus, boolean updateIndex) throws Exception {
metadataStatusRepository.save(metatatStatus);
metadataIndexer.indexMetadata(metatatStatus.getMetadataId() + "", true, IndexingMode.full);
if (updateIndex) {
metadataIndexer.indexMetadata(metatatStatus.getMetadataId() + "", true, IndexingMode.full);
}
return metatatStatus;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ protected String createDraft(ServiceContext context, String templateId, String g

List<MetadataStatus> listOfStatusChange = new ArrayList<>(1);
listOfStatusChange.add(metadataStatus);
sa.onStatusChange(listOfStatusChange);
sa.onStatusChange(listOfStatusChange, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void onEdit(int id, boolean minorEdit) throws Exception {
* @return
* @throws Exception
*/
public Map<Integer, StatusChangeType> onStatusChange(List<MetadataStatus> listOfStatus) throws Exception {
public Map<Integer, StatusChangeType> onStatusChange(List<MetadataStatus> listOfStatus, boolean updateIndex) throws Exception {

if (listOfStatus.stream().map(MetadataStatus::getMetadataId).distinct().count() != listOfStatus.size()) {
throw new IllegalArgumentException("Multiple status update received on the same metadata");
Expand Down Expand Up @@ -179,16 +179,7 @@ public Map<Integer, StatusChangeType> onStatusChange(List<MetadataStatus> listOf
context.debug("Change status of metadata with id " + status.getMetadataId() + " from " + currentStatusId + " to " + statusId);

// we know we are allowed to do the change, apply any side effects
boolean deleted = applyStatusChange(status.getMetadataId(), status, statusId);

// inform content reviewers if the status is submitted
try {
notify(getUserToNotify(status), status);
} catch (Exception e) {
context.warning(String.format(
"Failed to send notification on status change for metadata %s with status %s. Error is: %s",
status.getMetadataId(), status.getStatusValue().getId(), e.getMessage()));
}
boolean deleted = applyStatusChange(status.getMetadataId(), status, statusId, updateIndex);

if (deleted) {
results.put(status.getMetadataId(), StatusChangeType.DELETED);
Expand All @@ -208,6 +199,15 @@ public Map<Integer, StatusChangeType> onStatusChange(List<MetadataStatus> listOf
}
}

// inform content reviewers if the status is submitted
try {
notify(getUserToNotify(status), status);
} catch (Exception e) {
context.warning(String.format(
"Failed to send notification on status change for metadata %s with status %s. Error is: %s",
status.getMetadataId(), status.getStatusValue().getId(), e.getMessage()));
}

}

return results;
Expand All @@ -218,10 +218,10 @@ public Map<Integer, StatusChangeType> onStatusChange(List<MetadataStatus> listOf
* eg. if APPROVED, publish a record,
* if RETIRED, unpublish or delete the record.
*/
private boolean applyStatusChange(int metadataId, MetadataStatus status, String toStatusId) throws Exception {
private boolean applyStatusChange(int metadataId, MetadataStatus status, String toStatusId, boolean updateIndex) throws Exception {
boolean deleted = false;
if (!deleted) {
metadataStatusManager.setStatusExt(status);
metadataStatusManager.setStatusExt(status, updateIndex);
}
return deleted;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public interface StatusActions {

public void onEdit(int id, boolean minorEdit) throws Exception;

public Map<Integer, StatusChangeType> onStatusChange(List<MetadataStatus> status) throws Exception;
public Map<Integer, StatusChangeType> onStatusChange(List<MetadataStatus> status, boolean updateIndex) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public class Settings {
public static final String SYSTEM_ENABLE_ALL_THESAURUS = "system/metadata/allThesaurus";
public static final String SYSTEM_METADATA_THESAURUS_NAMESPACE = "system/metadata/thesaurusNamespace";
public static final String SYSTEM_METADATA_VALIDATION_REMOVESCHEMALOCATION = "system/metadata/validation/removeSchemaLocation";
public static final String SYSTEM_METADATA_HISTORY_ENABLED = "system/metadata/history/enabled";
public static final GNSetting SYSTEM_SITE_SVNUUID = new GNSetting("system/site/svnUuid", true);
public static final String SYSTEM_INTRANET_NETWORK = "system/intranet/network";
public static final String SYSTEM_INTRANET_NETMASK = "system/intranet/netmask";
Expand Down Expand Up @@ -139,6 +138,8 @@ public class Settings {
public static final String METADATA_IMPORT_RESTRICT = "metadata/import/restrict";
public static final String METADATA_IMPORT_USERPROFILE = "metadata/import/userprofile";
public static final String METADATA_BATCH_EDITING_ACCESS_LEVEL = "metadata/batchediting/accesslevel";
public static final String METADATA_HISTORY_ENABLED = "metadata/history/enabled";
public static final String METADATA_HISTORY_ACCESS_LEVEL = "metadata/history/accesslevel";
public static final String METADATA_PUBLISHED_DELETE_USERPROFILE = "metadata/delete/profilePublishedMetadata";
public static final String METADATA_PUBLISH_USERPROFILE = "metadata/publication/profilePublishMetadata";
public static final String METADATA_UNPUBLISH_USERPROFILE = "metadata/publication/profileUnpublishMetadata";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//=============================================================================
//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
//=== and United Nations Environment Programme (UNEP)
//===
Expand Down Expand Up @@ -30,14 +30,9 @@

import jeeves.server.context.ServiceContext;

import org.apache.commons.lang.NotImplementedException;
import org.fao.geonet.kernel.SchemaManager;
import org.fao.geonet.kernel.setting.SettingInfo;
import org.fao.geonet.utils.Log;
import org.fao.geonet.Util;

import org.fao.geonet.utils.Xml;
import org.apache.commons.lang.StringUtils;
import org.fao.geonet.GeonetContext;
import org.fao.geonet.constants.Geonet;
import org.fao.geonet.csw.common.Csw;
Expand All @@ -54,7 +49,6 @@
import org.fao.geonet.kernel.csw.CatalogService;
import org.fao.geonet.kernel.csw.services.AbstractOperation;
import org.fao.geonet.kernel.csw.services.getrecords.SearchController;
import org.fao.geonet.domain.Pair;
import org.fao.geonet.lib.Lib;
import org.jdom.Element;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -76,12 +70,14 @@ public class GetRecordById extends AbstractOperation implements CatalogService {
//---------------------------------------------------------------------------

static final String NAME = "GetRecordById";
private SearchController _searchController;

@Autowired
private SearchController searchController;
@Autowired
private CatalogConfiguration _catalogConfig;
private CatalogConfiguration catalogConfig;

@Autowired
private SchemaManager _schemaManager;
private SchemaManager schemaManager;

@Autowired
public GetRecordById(ApplicationContext applicationContext) {
Expand All @@ -106,7 +102,7 @@ public Element execute(Element request, ServiceContext context) throws CatalogEx
checkVersion(request);
//-- Added for CSW 2.0.2 compliance by [email protected]
checkOutputFormat(request);
String outSchema = OutputSchema.parse(request.getAttributeValue("outputSchema"), _schemaManager);
String outSchema = OutputSchema.parse(request.getAttributeValue("outputSchema"), schemaManager);
//--------------------------------------------------------

ElementSetName setName = getElementSetName(request, ElementSetName.SUMMARY);
Expand Down Expand Up @@ -135,8 +131,8 @@ public Element execute(Element request, ServiceContext context) throws CatalogEx
Lib.resource.checkPrivilege(context, id, ReservedOperation.view);

final String displayLanguage = context.getLanguage();
Element md = SearchController.retrieveMetadata(context, id, setName, outSchema, null, null, ResultType.RESULTS, null,
displayLanguage);
Element md = searchController.retrieveMetadata(context, id, setName, outSchema, null, null, ResultType.RESULTS,null,
displayLanguage, true);

if (md != null) {
final Map<String, GetRecordByIdMetadataTransformer> transformers = context.getApplicationContext()
Expand All @@ -150,7 +146,7 @@ public Element execute(Element request, ServiceContext context) throws CatalogEx

response.addContent(md);

if (_catalogConfig.isIncreasePopularity()) {
if (catalogConfig.isIncreasePopularity()) {
gc.getBean(DataManager.class).increasePopularity(context, id);
}
}
Expand Down
Loading

0 comments on commit f7b5bfe

Please sign in to comment.