11package edu .harvard .iq .dataverse .api ;
22
3- import com .fasterxml .jackson .databind .ObjectMapper ;
4- import edu .harvard .iq .dataverse .api .dto .NewDataverseFeaturedItemDTO ;
53import edu .harvard .iq .dataverse .util .json .NullSafeJsonBuilder ;
64import io .restassured .http .ContentType ;
75import io .restassured .path .json .JsonPath ;
5351import edu .harvard .iq .dataverse .settings .FeatureFlags ;
5452import edu .harvard .iq .dataverse .util .StringUtil ;
5553
56- import static org .apache .http .entity .ContentType .APPLICATION_JSON ;
5754import static org .junit .jupiter .api .Assertions .*;
5855
5956public class UtilIT {
@@ -767,14 +764,24 @@ static Response deleteDatasetMetadataViaNative(String persistentId, String pathT
767764
768765 static Response updateFieldLevelDatasetMetadataViaNative (String persistentId , String pathToJsonFile , String apiToken ) {
769766 String jsonIn = getDatasetJson (pathToJsonFile );
770- Response response = given ()
767+ return editVersionMetadataFromJsonStr (persistentId , jsonIn , apiToken , null );
768+ }
769+
770+ static Response editVersionMetadataFromJsonStr (String persistentId , String jsonString , String apiToken ) {
771+ return editVersionMetadataFromJsonStr (persistentId , jsonString , apiToken , null );
772+ }
773+
774+ static Response editVersionMetadataFromJsonStr (String persistentId , String jsonString , String apiToken , Integer sourceInternalVersionNumber ) {
775+ return given ()
771776 .header (API_TOKEN_HTTP_HEADER , apiToken )
772- .body (jsonIn )
777+ .body (jsonString )
773778 .contentType ("application/json" )
774- .put ("/api/datasets/:persistentId/editMetadata/?persistentId=" + persistentId + "&replace=true" );
775- return response ;
779+ .put ("/api/datasets/:persistentId/editMetadata/?persistentId="
780+ + persistentId
781+ + "&replace=true"
782+ + (sourceInternalVersionNumber != null ? "&sourceInternalVersionNumber=" + sourceInternalVersionNumber : "" ));
776783 }
777-
784+
778785 static Response updateDatasetPIDMetadata (String persistentId , String apiToken ) {
779786 Response response = given ()
780787 .header (API_TOKEN_HTTP_HEADER , apiToken )
@@ -1291,6 +1298,12 @@ static Response getFileData(String fileId, String apiToken, String datasetVersio
12911298 .get ("/api/files/" + fileId + "/versions/" + datasetVersionId );
12921299 }
12931300
1301+ static Response getFileVersionDifferences (String fileId , String apiToken ) {
1302+ return given ()
1303+ .header (API_TOKEN_HTTP_HEADER , apiToken )
1304+ .get ("/api/files/" + fileId + "/versionDifferences" );
1305+ }
1306+
12941307 static Response testIngest (String fileName , String fileType ) {
12951308 return given ()
12961309 .get ("/api/ingest/test/file?fileName=" + fileName + "&fileType=" + fileType );
@@ -2973,6 +2986,15 @@ static Response metricsDatasetsBySubjectToMonth(String month, String queryParams
29732986 return requestSpecification .get ("/api/info/metrics/datasets/bySubject/toMonth/" + month + optionalQueryParams );
29742987 }
29752988
2989+ public static Response makeDataCountMetricTimeSeries (String metricType , String queryParams ) {
2990+ String apiPath = "/api/v1/metrics/makeDataCount/" + metricType + "/monthly" ;
2991+
2992+ Response response = given ()
2993+ .get (apiPath + (queryParams != null && !queryParams .isEmpty () ? "?" + queryParams : "" ));
2994+
2995+ return response ;
2996+ }
2997+
29762998 static Response clearMetricCache () {
29772999 RequestSpecification requestSpecification = given ();
29783000 return requestSpecification .delete ("/api/admin/clearMetricsCache" );
@@ -3465,8 +3487,11 @@ static Response makeDataCountGetProcessingState(String yearMonth) {
34653487 return requestSpecification .get ("/api/admin/makeDataCount/" + yearMonth + "/processingState" );
34663488 }
34673489 static Response makeDataCountUpdateProcessingState (String yearMonth , String state ) {
3490+ return makeDataCountUpdateProcessingState (yearMonth , state , null );
3491+ }
3492+ static Response makeDataCountUpdateProcessingState (String yearMonth , String state , String server ) {
34683493 RequestSpecification requestSpecification = given ();
3469- return requestSpecification .post ("/api/admin/makeDataCount/" + yearMonth + "/processingState?state=" + state );
3494+ return requestSpecification .post ("/api/admin/makeDataCount/" + yearMonth + "/processingState?state=" + state + ( server != null ? "&server=" + server : "" ) );
34703495 }
34713496 static Response makeDataCountDeleteProcessingState (String yearMonth ) {
34723497 RequestSpecification requestSpecification = given ();
@@ -4276,6 +4301,18 @@ static Response getDownloadSize(Integer datasetId,
42764301 .get ("/api/datasets/" + datasetId + "/versions/" + version + "/downloadsize" );
42774302 }
42784303
4304+ static Response getDownloadCountByDatasetId (Integer datasetId , String apiToken , Boolean includeMDC ) {
4305+ RequestSpecification requestSpecification = given ();
4306+ if (apiToken != null ) {
4307+ requestSpecification .header (API_TOKEN_HTTP_HEADER , apiToken );
4308+ }
4309+ if (includeMDC != null ) {
4310+ requestSpecification = requestSpecification .queryParam ("includeMDC" , includeMDC );
4311+ }
4312+ return requestSpecification
4313+ .get ("/api/datasets/" + datasetId + "/download/count" );
4314+ }
4315+
42794316 static Response downloadTmpFile (String fullyQualifiedPathToFile , String apiToken ) {
42804317 return given ()
42814318 .header (API_TOKEN_HTTP_HEADER , apiToken )
@@ -4578,7 +4615,7 @@ static Response deleteDataverseFeaturedItems(String dataverseAlias, String apiTo
45784615 .header (API_TOKEN_HTTP_HEADER , apiToken )
45794616 .delete ("/api/dataverses/" + dataverseAlias + "/featuredItems" );
45804617 }
4581-
4618+
45824619 public static Response deleteDatasetFiles (String datasetId , JsonArray fileIds , String apiToken ) {
45834620 String path = String .format ("/api/datasets/%s/deleteFiles" , datasetId );
45844621 return given ()
@@ -4587,4 +4624,24 @@ public static Response deleteDatasetFiles(String datasetId, JsonArray fileIds, S
45874624 .body (fileIds .toString ())
45884625 .put (path );
45894626 }
4627+
4628+ public static Response updateDataverseInputLevelDisplayOnCreate (String dataverseAlias , String fieldTypeName , Boolean displayOnCreate , String apiToken ) {
4629+ JsonArrayBuilder inputLevelsArrayBuilder = Json .createArrayBuilder ();
4630+ JsonObjectBuilder inputLevel = Json .createObjectBuilder ()
4631+ .add ("datasetFieldTypeName" , fieldTypeName )
4632+ .add ("required" , false )
4633+ .add ("include" , true );
4634+ if (displayOnCreate != null ) {
4635+ inputLevel .add ("displayOnCreate" , displayOnCreate );
4636+ }
4637+
4638+ inputLevelsArrayBuilder .add (inputLevel );
4639+
4640+ return given ()
4641+ .header (API_TOKEN_HTTP_HEADER , apiToken )
4642+ .body (inputLevelsArrayBuilder .build ().toString ())
4643+ .contentType (ContentType .JSON )
4644+ .put ("/api/dataverses/" + dataverseAlias + "/inputLevels" );
4645+ }
4646+
45904647}
0 commit comments