Skip to content
Snippets Groups Projects
Commit 64753a56 authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Merge branch 'gc-patch-records' into 'master'

Added a new endpoint 'pathRecords'.

See merge request !691
parents 6e3e6412 6dac547c
No related branches found
No related tags found
4 merge requests!760Vulnerability fixes,!745Draft: M18 Upgraded packages to mitigate vulns in netty, guava, snakeyaml,!744Upgraded packages to mitigated vulns in netty, guava, snakeyaml,!691Added a new endpoint 'pathRecords'.
Pipeline #186345 canceled
/*
* Copyright 2020-2022 Google LLC
* Copyright 2020-2022 EPAM Systems, Inc
* Copyright 2020-2023 Google LLC
* Copyright 2020-2023 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.
......@@ -17,17 +17,7 @@
package org.opengroup.osdu.storage.provider.gcp.web.repository;
import static org.opengroup.osdu.core.gcp.osm.model.where.condition.And.and;
import static org.opengroup.osdu.core.gcp.osm.model.where.predicate.Eq.eq;
import static org.opengroup.osdu.core.gcp.osm.model.where.predicate.In.in;
import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_SINGLETON;
import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import com.github.fge.jsonpatch.JsonPatch;
import lombok.RequiredArgsConstructor;
import lombok.extern.java.Log;
import org.opengroup.osdu.core.common.model.http.CollaborationContext;
......@@ -43,9 +33,18 @@ import org.opengroup.osdu.core.gcp.osm.service.Transaction;
import org.opengroup.osdu.core.gcp.osm.translate.Outcome;
import org.opengroup.osdu.storage.provider.interfaces.IRecordsMetadataRepository;
import org.opengroup.osdu.storage.provider.interfaces.ISchemaRepository;
import org.opengroup.osdu.storage.util.JsonPatchUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import java.util.*;
import java.util.stream.Collectors;
import static org.opengroup.osdu.core.gcp.osm.model.where.condition.And.and;
import static org.opengroup.osdu.core.gcp.osm.model.where.predicate.Eq.eq;
import static org.opengroup.osdu.core.gcp.osm.model.where.predicate.In.in;
import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_SINGLETON;
@Repository
@Scope(SCOPE_SINGLETON)
@Log
......@@ -126,6 +125,27 @@ public class OsmRecordsMetadataRepository implements IRecordsMetadataRepository<
return queryByLegal(legalTagName, null, limit);
}
@Override
public Map<String, String> patch(
Map<RecordMetadata, JsonPatch> jsonPatchPerRecord,
Optional<CollaborationContext> collaborationContext) {
if (Objects.nonNull(jsonPatchPerRecord)) {
Transaction txn = context.beginTransaction(getDestination());
try {
for (RecordMetadata recordMetadata : jsonPatchPerRecord.keySet()) {
JsonPatch jsonPatch = jsonPatchPerRecord.get(recordMetadata);
RecordMetadata newRecordMetadata =
JsonPatchUtil.applyPatch(jsonPatch, RecordMetadata.class, recordMetadata);
context.upsert(newRecordMetadata, getDestination());
}
txn.commitIfActive();
} finally {
txn.rollbackIfActive();
}
}
return new HashMap<>();
}
private Destination getDestination() {
return Destination.builder().partitionId(tenantInfo.getDataPartitionId())
.namespace(new Namespace(tenantInfo.getName())).kind(RECORD_KIND).build();
......
/*
* Copyright 2020-2023 Google LLC
* Copyright 2020-2023 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.records;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.storage.util.AnthosTestUtils;
public class TestPatchRecords extends PatchRecordsTest {
@Before
@Override
public void setup() throws Exception {
this.testUtils = new AnthosTestUtils();
super.setup();
}
@After
@Override
public void tearDown() throws Exception {
super.tearDown();
this.testUtils = null;
}
}
/*
* Copyright 2020-2023 Google LLC
* Copyright 2020-2023 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.records;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.storage.util.GCPTestUtils;
public class TestPatchRecords extends PatchRecordsTest {
@Before
@Override
public void setup() throws Exception {
this.testUtils = new GCPTestUtils();
super.setup();
}
@After
@Override
public void tearDown() throws Exception {
super.tearDown();
this.testUtils = null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment