Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignoring special groups #26

Merged
merged 3 commits into from
Feb 27, 2024
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
5 changes: 5 additions & 0 deletions geonetwork-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
<artifactId>json</artifactId>
<version>20230618</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class GroupsHelper {
protected GroupsApi api;
protected Logger logger = LogManager.getLogger(TagsHelper.class);

// These are build in group and should not be removed
protected final List<String> buildInGroup = List.of("all", "intranet", "guest","sample");

@Autowired
ObjectMapper objectMapper;

Expand Down Expand Up @@ -99,7 +102,11 @@ public void deleteGroups() {
ResponseEntity<List<Group>> groups = api.getGroupsWithHttpInfo(Boolean.TRUE, null);
if(groups.getStatusCode().is2xxSuccessful()) {
Objects.requireNonNull(groups.getBody())
.forEach(f -> api.deleteGroupWithHttpInfo(f.getId(), true));
.forEach(f -> {
if (f.getName() != null && !buildInGroup.stream().anyMatch(e -> e.equalsIgnoreCase(f.getName()))) {
api.deleteGroupWithHttpInfo(f.getId(), true);
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
import org.apache.logging.log4j.Logger;
import org.json.JSONObject;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
import org.springframework.util.ResourceUtils;

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Optional;

import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.*;

public class GroupHelperTest {

Expand Down Expand Up @@ -63,4 +70,31 @@ public void verifyUpdateHarvestersOwnerGroup() throws IOException {
assertTrue("Own group updated and exist", i.isPresent());
assertEquals("Own group updated id is", i.get().getInt("id"),1234);
}
/**
* We do not want to delete any build in group as it cause issues.
* @throws IOException
*/
@Test
public void verfiyDeleteGroupKeepBuildInGroup() throws IOException {
// Check is equalIgnoreCase, so capital letter or not does not matter
Group all = new Group().name("All");
Group intranet = new Group().name("intranet");
Group guest = new Group().name("guest");
Group sample = new Group().name("SamplE");

// Should delete this only
Group toBeDeleted = new Group().name("To be deleted").id(1);

List<Group> groupList = List.of(all, intranet, guest, sample, toBeDeleted);

GroupsApi api = mock(GroupsApi.class);
Mockito.doReturn(ResponseEntity.ok(groupList))
.when(api)
.getGroupsWithHttpInfo(eq(Boolean.TRUE), isNull());

GroupsHelper helper = new GroupsHelper(api);
helper.deleteGroups();

verify(api, times(1)).deleteGroupWithHttpInfo(anyInt(), eq(true));
}
}
150 changes: 75 additions & 75 deletions geonetwork/src/main/java/au/org/aodn/geonetwork4/controller/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,88 +101,88 @@ public ResponseEntity<?> setup() {

setup.deleteAllHarvesters();
setup.insertHarvester(

"/config/harvesters/catalog_aodn/aad.json",
"/config/harvesters/catalog_aodn/aad_waf.json",
// "/config/harvesters/portal_catalogue_aad.json",

"/config/harvesters/catalog_aodn/aims.json",
// "/config/harvesters/portal_catalogue_aims.json",
// "/config/harvesters/portal_catalogue_aims_gbr_genomics_database_seawater_illumina_reads.json",
// "/config/harvesters/portal_catalogue_aims_microdebris_contamination.json",
// "/config/harvesters/portal_catalogue_aims_mmp.json",
// "/config/harvesters/portal_catalogue_aims_weather_station.json",

"/config/harvesters/catalog_aodn/csiro_oceans_atmosphere.json",
// "/config/harvesters/portal_catalogue_csiro_adcp.json",
// "/config/harvesters/portal_catalogue_csiro_catch_operations.json",
// "/config/harvesters/portal_catalogue_csiro_current_meter_mooring.json",
// "/config/harvesters/portal_catalogue_csiro_mnf_voyage_tracks.json",
// "/config/harvesters/portal_catalogue_csiro_o_and_a_ctd_data_overview.json",
// "/config/harvesters/portal_catalogue_csiro_o_and_a_hydrology_data_overview.json",
// "/config/harvesters/portal_catalogue_csiro_rv_franklin_xbt.json",
// "/config/harvesters/portal_catalogue_csiro_rv_investigator_data_overview.json",
// "/config/harvesters/portal_catalogue_csiro_rv_investigator_sst.json",
// "/config/harvesters/portal_catalogue_csiro_rv_southern_surveyor.json",
// "/config/harvesters/portal_catalogue_csiro_sediment_sampling.json",
// "/config/harvesters/portal_catalogue_csiro_wildlife_observations.json",
// "/config/harvesters/portal_catalogue_ga_marine_sediments_mars_database.json",
// "/config/harvesters/catalogue_csiro_southern_surveyor.json",

"/config/harvesters/catalog_aodn/ga_marine1.json",
"/config/harvesters/catalog_aodn/ga_marine2.json",
// "/config/harvesters/catalogue_ga_mh370.json",
// "/config/harvesters/catalogue_ga_seabed_sediments.json",
// "/config/harvesters/portal_catalogue_ga_mh370_phase_1_150m_bathymetry.json",

"/config/harvesters/catalog_aodn/imos_geonetwork.json",
// "/config/harvesters/portal_catalogue_imas_aodn_portal.json",
// "/config/harvesters/catalogue_oeh_aodn_portal.json",
// "/config/harvesters/catalogue_imas_aodn_portal.json",
// "/config/harvesters/portal_catalogue_oeh_aodn_portal.json",
// "/config/harvesters/portal_catalogue_uwa_aodn_portal.json"

"/config/harvesters/catalog_aodn/imos_geonetwork.json",
"/config/harvesters/catalogue_full_from_geo2_to_geo3.json",
"/config/harvesters/portal_catalogue_imos.json",
"/config/harvesters/catalogue_cdu_eretmochelys_imbricata.json",
"/config/harvesters/catalogue_cdu_lepidochelys_olivacea.json",
"/config/harvesters/catalogue_csiro_australian_weekly.json",
"/config/harvesters/catalogue_csiro_wakmatha.json",
"/config/harvesters/catalogue_csiro_world_monthly.json",
"/config/harvesters/catalogue_noaa.json",
"/config/harvesters/catalogue_csiro_the_australian_phytoplankton_database.json",
"/config/harvesters/catalogue_csiro_ocean_acid_recon.json",
"/config/harvesters/catalogue_dsto.json",
"/config/harvesters/catalogue_full.json",
"/config/harvesters/catalogue_imas_aqua_chlorophyll_concentration_monthly.json",
"/config/harvesters/catalogue_imas_aqua_chlorophyll_concentration_weekly.json",
"/config/harvesters/catalogue_imas_seaWIFS_chlorophyll_concentration_monthly.json",
"/config/harvesters/catalogue_imas_seaWIFS_chlorophyll_concentration_weekly.json",
"/config/harvesters/catalogue_mhl_sea_surface_temperature_data.json",
"/config/harvesters/catalogue_mhl_waverider_buoys.json",
"/config/harvesters/catalogue_nsw_oeh_bathy.json",
"/config/harvesters/catalogue_ran.json",
"/config/harvesters/catalogue_wamsi_ningaloo_reef.json",
"/config/harvesters/catalogue_imos.json",
"/config/harvesters/catalogue_imos_portal.json",

"/config/harvesters/catalogue_tpac_climate_futures.json"

// "/config/harvesters/portal_catalogue_niwa.json",
// "/config/harvesters/portal_catalogue_systest.json"

// copy prod to systest
// "/config/harvesters/catalogue_portal.json",
"/config/harvesters/portal_catalogue_imos.json",
"config/harvesters/portal_catalogue_aims.json"
// "/config/harvesters/catalog_aodn/aad.json",
// "/config/harvesters/catalog_aodn/aad_waf.json",
//// "/config/harvesters/portal_catalogue_aad.json",
//
// "/config/harvesters/catalog_aodn/aims.json",
//// "/config/harvesters/portal_catalogue_aims.json",
//// "/config/harvesters/portal_catalogue_aims_gbr_genomics_database_seawater_illumina_reads.json",
//// "/config/harvesters/portal_catalogue_aims_microdebris_contamination.json",
//// "/config/harvesters/portal_catalogue_aims_mmp.json",
//// "/config/harvesters/portal_catalogue_aims_weather_station.json",
//
// "/config/harvesters/catalog_aodn/csiro_oceans_atmosphere.json",
//// "/config/harvesters/portal_catalogue_csiro_adcp.json",
//// "/config/harvesters/portal_catalogue_csiro_catch_operations.json",
//// "/config/harvesters/portal_catalogue_csiro_current_meter_mooring.json",
//// "/config/harvesters/portal_catalogue_csiro_mnf_voyage_tracks.json",
//// "/config/harvesters/portal_catalogue_csiro_o_and_a_ctd_data_overview.json",
//// "/config/harvesters/portal_catalogue_csiro_o_and_a_hydrology_data_overview.json",
//// "/config/harvesters/portal_catalogue_csiro_rv_franklin_xbt.json",
//// "/config/harvesters/portal_catalogue_csiro_rv_investigator_data_overview.json",
//// "/config/harvesters/portal_catalogue_csiro_rv_investigator_sst.json",
//// "/config/harvesters/portal_catalogue_csiro_rv_southern_surveyor.json",
//// "/config/harvesters/portal_catalogue_csiro_sediment_sampling.json",
//// "/config/harvesters/portal_catalogue_csiro_wildlife_observations.json",
//// "/config/harvesters/portal_catalogue_ga_marine_sediments_mars_database.json",
//// "/config/harvesters/catalogue_csiro_southern_surveyor.json",
//
// "/config/harvesters/catalog_aodn/ga_marine1.json",
// "/config/harvesters/catalog_aodn/ga_marine2.json",
//// "/config/harvesters/catalogue_ga_mh370.json",
//// "/config/harvesters/catalogue_ga_seabed_sediments.json",
//// "/config/harvesters/portal_catalogue_ga_mh370_phase_1_150m_bathymetry.json",
//
// "/config/harvesters/catalog_aodn/imos_geonetwork.json",
//// "/config/harvesters/portal_catalogue_imas_aodn_portal.json",
//// "/config/harvesters/catalogue_oeh_aodn_portal.json",
//// "/config/harvesters/catalogue_imas_aodn_portal.json",
//// "/config/harvesters/portal_catalogue_oeh_aodn_portal.json",
//// "/config/harvesters/portal_catalogue_uwa_aodn_portal.json"
//
// "/config/harvesters/catalog_aodn/imos_geonetwork.json",
// "/config/harvesters/catalogue_full_from_geo2_to_geo3.json",
// "/config/harvesters/portal_catalogue_imos.json",
// "/config/harvesters/catalogue_cdu_eretmochelys_imbricata.json",
// "/config/harvesters/catalogue_cdu_lepidochelys_olivacea.json",
// "/config/harvesters/catalogue_csiro_australian_weekly.json",
// "/config/harvesters/catalogue_csiro_wakmatha.json",
// "/config/harvesters/catalogue_csiro_world_monthly.json",
// "/config/harvesters/catalogue_noaa.json",
// "/config/harvesters/catalogue_csiro_the_australian_phytoplankton_database.json",
// "/config/harvesters/catalogue_csiro_ocean_acid_recon.json",
// "/config/harvesters/catalogue_dsto.json",
// "/config/harvesters/catalogue_full.json",
// "/config/harvesters/catalogue_imas_aqua_chlorophyll_concentration_monthly.json",
// "/config/harvesters/catalogue_imas_aqua_chlorophyll_concentration_weekly.json",
// "/config/harvesters/catalogue_imas_seaWIFS_chlorophyll_concentration_monthly.json",
// "/config/harvesters/catalogue_imas_seaWIFS_chlorophyll_concentration_weekly.json",
// "/config/harvesters/catalogue_mhl_sea_surface_temperature_data.json",
// "/config/harvesters/catalogue_mhl_waverider_buoys.json",
// "/config/harvesters/catalogue_nsw_oeh_bathy.json",
// "/config/harvesters/catalogue_ran.json",
// "/config/harvesters/catalogue_wamsi_ningaloo_reef.json",
// "/config/harvesters/catalogue_imos.json",
// "/config/harvesters/catalogue_imos_portal.json",
//
// "/config/harvesters/catalogue_tpac_climate_futures.json"
//
//// "/config/harvesters/portal_catalogue_niwa.json",
//// "/config/harvesters/portal_catalogue_systest.json"
//
//// copy prod to systest
//// "/config/harvesters/catalogue_portal.json",
);

setup.insertUsers(
"/config/users/admin.json"
);

ResponseEntity<List<Status>> response = setup.insertGroups(
"/config/groups/aodn.json",
"config/groups/sample.json"
"/config/groups/aodn.json"
);

return ResponseEntity.of(Optional.of(response.getStatusCodeValue()));
Expand Down
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<swagger.version>2.2.15</swagger.version>
<javax.validation.version>2.0.1.Final</javax.validation.version>
<aws.sts.version>1.12.261</aws.sts.version>
<jackson.nullable.version>0.2.6</jackson.nullable.version>
<mockito.version>5.10.0</mockito.version>

<versioning.updatePom>true</versioning.updatePom>
</properties>
<repositories>
Expand Down Expand Up @@ -78,7 +81,12 @@
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.6</version>
<version>${jackson.nullable.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
2 changes: 1 addition & 1 deletion startEsLocal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ fi

# If you run in EC2, you need to change the docker-es-compose.yml localhost in cert to the hostname of EC2 and install docker
# docker-compose and sudo chmod 666 /run/docker.sock
docker-compose -f docker-es-compose.yml up --detach --remove-orphans
docker-compose -f docker-es-compose.yml up --detach --remove-orphans --force-recreate