Skip to content

Commit

Permalink
Merge branch 'geonetwork:main' into translations-update-por-iso19139
Browse files Browse the repository at this point in the history
  • Loading branch information
julianofinck authored Nov 30, 2024
2 parents 7a578a7 + 5e6f08f commit 60dc281
Show file tree
Hide file tree
Showing 26 changed files with 717 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public String toString() {

private String escapeResourceManagementExternalProperties(String value) {
return value.replace(RESOURCE_MANAGEMENT_EXTERNAL_PROPERTIES_SEPARATOR, RESOURCE_MANAGEMENT_EXTERNAL_PROPERTIES_ESCAPED_SEPARATOR);
}
}

/**
* Create an encoded base 64 object id contains the following fields to uniquely identify the resource
Expand Down
45 changes: 17 additions & 28 deletions core/src/main/java/org/fao/geonet/kernel/SelectionManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001-2016 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 @@ -51,30 +51,30 @@
* Manage objects selection for a user session.
*/
public class SelectionManager {

public static final String SELECTION_METADATA = "metadata";
public static final String SELECTION_BUCKET = "bucket";
// Bucket name used in the search UI to store the selected the metadata
public static final String SELECTION_BUCKET = "s101";
// used to limit select all if get system setting maxrecords fails or contains value we can't parse
public static final int DEFAULT_MAXHITS = 1000;
public static final String ADD_ALL_SELECTED = "add-all";
public static final String REMOVE_ALL_SELECTED = "remove-all";
public static final String ADD_SELECTED = "add";
public static final String REMOVE_SELECTED = "remove";
public static final String CLEAR_ADD_SELECTED = "clear-add";
private Hashtable<String, Set<String>> selections = null;
private Hashtable<String, Set<String>> selections;

private SelectionManager() {
selections = new Hashtable<String, Set<String>>(0);
selections = new Hashtable<>(0);

Set<String> MDSelection = Collections
.synchronizedSet(new HashSet<String>(0));
.synchronizedSet(new HashSet<>(0));
selections.put(SELECTION_METADATA, MDSelection);
}


public Map<String, Integer> getSelectionsAndSize() {
return selections.entrySet().stream().collect(Collectors.toMap(
e -> e.getKey(),
Map.Entry::getKey,
e -> e.getValue().size()
));
}
Expand Down Expand Up @@ -183,7 +183,7 @@ public int updateSelection(String type,
// Get the selection manager or create it
Set<String> selection = this.getSelection(type);
if (selection == null) {
selection = Collections.synchronizedSet(new HashSet<String>());
selection = Collections.synchronizedSet(new HashSet<>());
this.selections.put(type, selection);
}

Expand All @@ -192,30 +192,21 @@ public int updateSelection(String type,
this.selectAll(type, context, session);
else if (selected.equals(REMOVE_ALL_SELECTED))
this.close(type);
else if (selected.equals(ADD_SELECTED) && listOfIdentifiers.size() > 0) {
else if (selected.equals(ADD_SELECTED) && !listOfIdentifiers.isEmpty()) {
// TODO ? Should we check that the element exist first ?
for (String paramid : listOfIdentifiers) {
selection.add(paramid);
}
} else if (selected.equals(REMOVE_SELECTED) && listOfIdentifiers.size() > 0) {
selection.addAll(listOfIdentifiers);
} else if (selected.equals(REMOVE_SELECTED) && !listOfIdentifiers.isEmpty()) {
for (String paramid : listOfIdentifiers) {
selection.remove(paramid);
}
} else if (selected.equals(CLEAR_ADD_SELECTED) && listOfIdentifiers.size() > 0) {
} else if (selected.equals(CLEAR_ADD_SELECTED) && !listOfIdentifiers.isEmpty()) {
this.close(type);
for (String paramid : listOfIdentifiers) {
selection.add(paramid);
}
selection.addAll(listOfIdentifiers);
}
}

// Remove empty/null element from the selection
Iterator<String> iter = selection.iterator();
while (iter.hasNext()) {
Object element = iter.next();
if (element == null)
iter.remove();
}
selection.removeIf(Objects::isNull);

return selection.size();
}
Expand All @@ -241,14 +232,12 @@ public void selectAll(String type, ServiceContext context, UserSession session)

if (StringUtils.isNotEmpty(type)) {
JsonNode request = (JsonNode) session.getProperty(Geonet.Session.SEARCH_REQUEST + type);
if (request == null) {
return;
} else {
if (request != null) {
final SearchResponse searchResponse;
try {
EsSearchManager searchManager = context.getBean(EsSearchManager.class);
searchResponse = searchManager.query(request.get("query"), FIELDLIST_UUID, 0, maxhits);
List<String> uuidList = new ArrayList();
List<String> uuidList = new ArrayList<>();
ObjectMapper objectMapper = new ObjectMapper();
for (Hit h : (List<Hit>) searchResponse.hits().hits()) {
uuidList.add((String) objectMapper.convertValue(h.source(), Map.class).get(Geonet.IndexFieldNames.UUID));
Expand Down Expand Up @@ -293,7 +282,7 @@ public Set<String> getSelection(String type) {
Set<String> sel = selections.get(type);
if (sel == null) {
Set<String> MDSelection = Collections
.synchronizedSet(new HashSet<String>(0));
.synchronizedSet(new HashSet<>(0));
selections.put(type, MDSelection);
}
return selections.get(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,14 +779,14 @@ public String toString() {
}

protected static class ResourceHolderImpl implements ResourceHolder {
private CmisObject cmisObject;
private final CmisObject cmisObject;
private Path tempFolderPath;
private Path path;
private final MetadataResource metadataResource;

public ResourceHolderImpl(final CmisObject cmisObject, MetadataResource metadataResource) throws IOException {
// Preserve filename by putting the files into a temporary folder and using the same filename.
tempFolderPath = Files.createTempDirectory("gn-meta-res-" + String.valueOf(metadataResource.getMetadataId() + "-"));
tempFolderPath = Files.createTempDirectory("gn-meta-res-" + metadataResource.getMetadataId() + "-");
tempFolderPath.toFile().deleteOnExit();
path = tempFolderPath.resolve(getFilename(cmisObject.getName()));
this.metadataResource = metadataResource;
Expand Down Expand Up @@ -817,11 +817,5 @@ public void close() throws IOException {
path=null;
tempFolderPath = null;
}

@Override
protected void finalize() throws Throwable {
close();
super.finalize();
}
}
}
Loading

0 comments on commit 60dc281

Please sign in to comment.