Commit 2d465ab3 authored by Dmitriy Rudko's avatar Dmitriy Rudko 💬
Browse files

Merge branch 'gcp-tags-records' into 'master'

GCP release/0.7 hotfix tags records

See merge request !157
parents 9cdbe20b da233651
Pipeline #31612 passed with stages
in 33 minutes and 26 seconds
// Copyright 2017-2019, Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.storage.provider.gcp;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.cloud.Timestamp;
import org.opengroup.osdu.core.gcp.multitenancy.IDatastoreFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.google.cloud.datastore.Cursor;
import com.google.cloud.datastore.Entity;
import com.google.cloud.datastore.FullEntity;
......@@ -41,17 +32,31 @@ import com.google.cloud.datastore.StringValue;
import com.google.cloud.datastore.StructuredQuery;
import com.google.cloud.datastore.Value;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import io.jsonwebtoken.lang.Collections;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import lombok.extern.java.Log;
import org.opengroup.osdu.core.common.model.entitlements.Acl;
import org.opengroup.osdu.core.common.model.legal.Legal;
import org.opengroup.osdu.core.common.model.legal.LegalCompliance;
import org.opengroup.osdu.core.common.model.storage.RecordAncestry;
import org.opengroup.osdu.core.common.model.storage.RecordMetadata;
import org.opengroup.osdu.core.common.model.storage.RecordState;
import org.opengroup.osdu.core.common.model.entitlements.Acl;
import org.opengroup.osdu.core.gcp.multitenancy.IDatastoreFactory;
import org.opengroup.osdu.storage.provider.interfaces.IRecordsMetadataRepository;
import io.jsonwebtoken.lang.Collections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@Repository
@Log
public class DatastoreRecordsMetadataRepository implements IRecordsMetadataRepository<Cursor> {
public static final String RECORD_KIND = "StorageRecord";
......@@ -75,6 +80,7 @@ public class DatastoreRecordsMetadataRepository implements IRecordsMetadataRepos
public static final String ANCESTRY = "ancestry";
public static final String ANCESTRY_PARENTS = "parents";
public static final String TAGS = "tags";
@Autowired
private IDatastoreFactory datastoreFactory;
......@@ -185,6 +191,14 @@ public class DatastoreRecordsMetadataRepository implements IRecordsMetadataRepos
recordMetadata.setModifyUser(entity.getString(MODIFY_USER));
}
if (entity.contains(TAGS)) {
String tags = entity.getString(TAGS);
if (!tags.isEmpty()) {
Map tagsMap = new Gson().fromJson(tags, Map.class);
recordMetadata.setTags(tagsMap);
}
}
if (entity.contains(MODIFY_TIME)) {
recordMetadata.setModifyTime(TimeUnit.SECONDS.toMillis(entity.getTimestamp(MODIFY_TIME).getSeconds())
+ TimeUnit.NANOSECONDS.toMillis(entity.getTimestamp(MODIFY_TIME).getNanos()));
......@@ -222,6 +236,15 @@ public class DatastoreRecordsMetadataRepository implements IRecordsMetadataRepos
.set(ANCESTRY_PARENTS, this.buildEntityArray(record.getAncestry().getParents())).build());
}
log.info(String.format("Record Tags = %s", record.getTags()));
if (record.getTags() != null && !record.getTags().isEmpty()) {
try {
entityBuilder.set(TAGS, new ObjectMapper().writeValueAsString(record.getTags()));
} catch (JsonProcessingException e) {
log.warning(e.getMessage());
}
}
if (record.getModifyTime() > 0) {
entityBuilder.set(MODIFY_TIME, Timestamp.ofTimeMicroseconds(TimeUnit.MILLISECONDS.toMicros(record.getModifyTime())));
}
......
......@@ -3,7 +3,7 @@ LOG_PREFIX=storage
osdu.gcp.storage.gcs.enable-impersonalization=false
server.servlet.contextPath=/api/storage/v2/
logging.level.org.springframework.web=DEBUG
logging.level.org.springframework.web={LOG_LEVEL:DEBUG}
server.port=8080
JAVA_HEAP_OPTS=-Xms4096M -Xmx4096M
JAVA_GC_OPTS=-XX:+UseG1GC -XX:+UseStringDeduplication -XX:InitiatingHeapOccupancyPercent=45
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<logger name="org.opengroup.osdu" level="DEBUG"/>
<springProfile name="local">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
......@@ -8,7 +9,7 @@
<charset>utf8</charset>
</encoder>
</appender>
<root level="DEBUG">
<root level="info">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
......@@ -28,9 +29,9 @@
</encoder>
</appender>
<root level="debug">
<root level="info">
<appender-ref ref="stdout"/>
</root>
</springProfile>
</configuration>
\ No newline at end of file
</configuration>
......@@ -53,6 +53,7 @@ public class RecordApiTest {
private final String USER = "user";
private final String TENANT = "tenant1";
private final String RECORD_ID = "osdu:anyID:any";
@Mock
private IngestionService ingestionService;
......@@ -125,8 +126,6 @@ public class RecordApiTest {
@Test
public void should_returnHttp200_when_gettingRecordVersionsSuccessfully() {
final String RECORD_ID = "anyID";
List<Long> versions = new ArrayList<Long>();
versions.add(1L);
versions.add(2L);
......@@ -149,8 +148,6 @@ public class RecordApiTest {
@Test
public void should_returnHttp204_when_purgingRecordSuccessfully() {
final String RECORD_ID = "anyID";
ResponseEntity response = this.sut.purgeRecord(RECORD_ID);
assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatusCodeValue());
......@@ -158,8 +155,6 @@ public class RecordApiTest {
@Test
public void should_returnHttp200_when_gettingTheLatestVersionOfARecordSuccessfully() {
final String RECORD_ID = "anyID";
when(this.queryService.getRecordInfo(RECORD_ID, new String[] {})).thenReturn(RECORD_ID);
ResponseEntity response = this.sut.getLatestRecordVersion(RECORD_ID, new String[] {});
......@@ -172,10 +167,9 @@ public class RecordApiTest {
@Test
public void should_returnHttp200_when_gettingSpecificVersionOfARecordSuccessfully() {
final String RECORD_ID = "anyID";
final long VERSION = 1L;
String expectedRecord = "{\"id\": \"anyID\",\r\n\"version\": 1}";
String expectedRecord = "{\"id\": \"osdu:anyID:any\",\r\n\"version\": 1}";
when(this.queryService.getRecordInfo(RECORD_ID, VERSION, new String[] {})).thenReturn(expectedRecord);
......@@ -190,8 +184,6 @@ public class RecordApiTest {
@Test
public void should_returnHttp204_when_deletingRecordSuccessfully() {
final String RECORD_ID = "anyID";
ResponseEntity response = this.sut.deleteRecord(RECORD_ID);
assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatusCodeValue());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment