Commit 17dab800 authored by harshit aggarwal's avatar harshit aggarwal
Browse files

using latest version param for schemas

parent a97fc97d
Pipeline #18119 failed with stages
in 18 seconds
......@@ -35,10 +35,10 @@ public class StatusStoreServiceImpl implements StatusStoreService {
RelationshipStatusDoc doc = new RelationshipStatusDoc(relationshipStatus);
try {
cosmosStore.upsertItem(requestIdentity.getDataPartitionId(), cosmosContainerConfig.getDatabase(), cosmosContainerConfig.getRelationshipStatusContainer(), requestIdentity.getDataPartitionId(), doc);
cosmosStore.upsertItem(requestIdentity.getDataPartitionId(), cosmosContainerConfig.getDatabase(), cosmosContainerConfig.getRelationshipStatusContainer(), doc.getId(), doc);
}
catch (AppException exception) {
LOGGER.error("Status update failed for Record ID: {} with exception {}", relationshipStatus.getRawRecordId(), exception.getError().getMessage());
LOGGER.error("Status update failed for Record ID: {} and Mapping ID: {} with exception {}", relationshipStatus.getRawRecordId(), relationshipStatus.getMappingId(), exception.getError().getMessage());
}
}
}
......
......@@ -13,6 +13,7 @@ import org.opengroup.osdu.wks.model.RelationshipStatus;
import org.opengroup.osdu.wks.provider.azure.di.CosmosContainerConfig;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.lenient;
......@@ -86,21 +87,21 @@ public class StatusStoreServiceImplTest {
List<RelationshipStatus> relationshipStatusList = Arrays.asList(relationshipStatus1, relationshipStatus2);
doNothing().when(cosmosStore)
.upsertItem(eq(DATA_PARTITION_ID), eq(DATABASE_NAME), eq(CONTAINER_NAME), eq(DATA_PARTITION_ID), any());
.upsertItem(eq(DATA_PARTITION_ID), eq(DATABASE_NAME), eq(CONTAINER_NAME), anyString(), any());
statusStoreService.createOrUpdateStoreEntry(relationshipStatusList);
verify(containerConfig, times(2)).getRelationshipStatusContainer();
verify(containerConfig, times(2)).getDatabase();
verify(requestIdentity, times(4)).getDataPartitionId();
verify(requestIdentity, times(2)).getDataPartitionId();
verify(relationshipStatus1, times(2)).getRawRecordId();
verify(relationshipStatus1, times(1)).getRawRecordId();
verify(relationshipStatus1, times(1)).getRawRecordVersion();
verify(relationshipStatus1, times(1)).getMappingId();
verify(relationshipStatus1, times(1)).getMappingId();
verify(relationshipStatus1, times(1)).getPendingIds();
verify(relationshipStatus1, times(1)).getPendingEntities();
verify(relationshipStatus2, times(2)).getRawRecordId();
verify(relationshipStatus2, times(1)).getRawRecordId();
verify(relationshipStatus2, times(1)).getRawRecordVersion();
verify(relationshipStatus2, times(1)).getMappingId();
verify(relationshipStatus2, times(1)).getMappingId();
......
......@@ -5,6 +5,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.apache.http.HttpStatus;
import org.apache.http.client.utils.URIBuilder;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.wks.config.RequestIdentity;
......@@ -16,17 +17,17 @@ import org.opengroup.osdu.wks.provider.interfaces.UserCredential;
import org.opengroup.osdu.wks.util.KindUtil;
import org.opengroup.osdu.wks.util.RestClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
@Component
public class SchemaService implements ISchemaService{
public static final String SCHEMA_SERVICE_ERROR_MESSAGE = "Schema service status code %s and message %s";
private static final String SCHEMA_SERVICE_ERROR_MESSAGE = "Schema service status code %s and message %s";
@Autowired
private RestClient restClient;
......@@ -40,8 +41,7 @@ public class SchemaService implements ISchemaService{
@Autowired
private RequestIdentity requestIdentity;
@Value("${SCHEMA_API}/schema")
private String schemaServiceUrl;
private final String schemaServiceUrl = getEnvironmentVariableOrDefaultValue("SCHEMA_API", "https://domain-name.org") + "/schema";
@Autowired
private KindUtil kindUtil;
......@@ -95,11 +95,30 @@ public class SchemaService implements ISchemaService{
return kinds;
}
private String getRequestURL(String kind) {
String[] kindArr = kind.split(Constants.COLON_SEPARATOR);
String majorVersion = kindUtil.getMajorVersionFromKind(kind).toString();
private String getRequestURL(String kind) throws ApplicationException {
try {
String[] kindArr = kind.split(Constants.COLON_SEPARATOR);
String majorVersion = kindUtil.getMajorVersionFromKind(kind).toString();
URIBuilder uriBuilder = new URIBuilder(schemaServiceUrl);
uriBuilder.addParameter("authority", kindArr[0]);
uriBuilder.addParameter("source", kindArr[1]);
uriBuilder.addParameter("entityType", kindArr[2]);
uriBuilder.addParameter("schemaVersionMajor", majorVersion);
uriBuilder.addParameter("latestVersion", "true");
return uriBuilder.build().toString();
}
catch (URISyntaxException exception) {
throw new ApplicationException(exception.getMessage());
}
return schemaServiceUrl + "?authority=" + kindArr[0] + "&source=" + kindArr[1] + "&entityType=" + kindArr[2] +
"&schemaVersionMajor=" + majorVersion;
}
private static String getEnvironmentVariableOrDefaultValue(String key, String defaultValue) {
String environmentVariable = System.getProperty(key, System.getenv(key));
if (environmentVariable == null) {
environmentVariable = defaultValue;
}
return environmentVariable;
}
}
......@@ -172,24 +172,13 @@ public class WKSServiceImpl implements WKSService {
private List<MappingsModel> updateMappingsWithLatestMinorAndPatchVersions(List<MappingsModel> mappingsList) throws ApplicationException {
for (MappingsModel mappingsModel : mappingsList) {
List<String> schemaKinds = schemaService.getSchemas(mappingsModel.getTargetSchemaKind());
List<String> schemaKindsWithLatestMinorAndPatchVersions = sortSchemasOnMinorAndPatchVersion(schemaKinds);
List<String> schemaKindsWithLatestMinorAndPatchVersions = schemaService.getSchemas(mappingsModel.getTargetSchemaKind());
mappingsModel.setTargetSchemaKind(schemaKindsWithLatestMinorAndPatchVersions.get(0));
}
log.log(Level.INFO, "Schemas for WKS fetched with latest minor and patch versions");
return mappingsList;
}
private List<String> sortSchemasOnMinorAndPatchVersion(List<String> schemaKinds) {
return schemaKinds.stream()
.sorted((a, b) -> {
String versionA = kindUtil.getVersionFromKind(a);
String versionB = kindUtil.getVersionFromKind(b);
return versionB.compareTo(versionA);
})
.collect(Collectors.toList());
}
private void initializeMessageContext(String dataPartitionId, String correlationId) {
requestIdentity.setDataPartitionId(dataPartitionId);
requestIdentity.setCorrelationId(correlationId);
......
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