Skip to content
Snippets Groups Projects
Commit b55a58a7 authored by MIchael Nguyen's avatar MIchael Nguyen
Browse files

mino refactor.

parent a487e621
No related branches found
No related tags found
1 merge request!6Trusted ibm
......@@ -10,6 +10,8 @@ import org.springframework.stereotype.Component;
@Component
public class ElasticRepositoryImpl implements ElasticRepository {
// TODO: Will need to be implemented later
@Value("${aws.es.host}")
String host;
......
......@@ -35,10 +35,7 @@ public class PublisherImpl implements IPublisher {
public void publishStatusChangedTagsToTopic(DpsHeaders headers, JobStatus indexerBatchStatus) throws Exception
{
String json = new Gson().toJson(indexerBatchStatus.getStatusesList());
// attributes
// Attributes
Map<String, MessageAttributeValue> messageAttributes = new HashMap<>();
messageAttributes.put(DpsHeaders.ACCOUNT_ID, new MessageAttributeValue()
.withDataType("String")
......
......@@ -7,9 +7,11 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.opengroup.osdu.is.core.logging.JaxRsDpsLog;
import org.opengroup.osdu.is.core.util.AppException;
import javax.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Set;
public class LegalTagsTypeConverter implements DynamoDBTypeConverter<String, Set<String>> {
......@@ -21,29 +23,31 @@ private JaxRsDpsLog logger;
// Converts an array of legaltag strings to a JSON string for DynamoDB
public String convert(Set<String> legaltags) {
ObjectMapper objectMapper = new ObjectMapper();
String converted;
try {
return objectMapper.writeValueAsString(legaltags);
converted = objectMapper.writeValueAsString(legaltags);
} catch (JsonProcessingException e) {
logger.error(String.format("There was an error converting the schema to a JSON string. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getOriginalMessage(), e);
}
return null;
return converted;
}
@Override
// Converts a JSON string of an array of legaltag strings to a list of legaltag strings
public Set<String> unconvert(String legaltagsString) {
ObjectMapper objectMapper = new ObjectMapper();
Set<String> unconvertedStrings;
try {
return objectMapper.readValue(legaltagsString, new TypeReference<Set<String>>(){});
unconvertedStrings = objectMapper.readValue(legaltagsString, new TypeReference<Set<String>>(){});
} catch (JsonParseException e) {
logger.error(String.format("There was an error parsing the legaltags JSON string. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getOriginalMessage(), e);
} catch (JsonMappingException e) {
logger.error(String.format("There was an error mapping the legaltags JSON string. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getOriginalMessage(), e);
} catch (IOException e) {
logger.error(String.format("There was an IO exception while mapping the legaltags objects. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getLocalizedMessage(), e);
} catch (Exception e) {
logger.error(String.format("There was an unknown exception legaltags the schema. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getLocalizedMessage(), e);
}
return null;
return unconvertedStrings;
}
}
......@@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.opengroup.osdu.indexer.aws.model.RecordMetadata;
import org.opengroup.osdu.indexer.aws.model.RecordMetadataDoc;
import org.opengroup.osdu.is.core.logging.JaxRsDpsLog;
import org.opengroup.osdu.is.core.util.AppException;
import javax.inject.Inject;
import java.io.IOException;
......@@ -23,12 +24,13 @@ public class RecordMetadataTypeConverter implements DynamoDBTypeConverter<String
// Converts RecordMetadata to a JSON string for DynamoDB
public String convert(RecordMetadata recordMetadata) {
ObjectMapper objectMapper = new ObjectMapper();
String convertedString;
try {
return objectMapper.writeValueAsString(recordMetadata);
convertedString = objectMapper.writeValueAsString(recordMetadata);
} catch (JsonProcessingException e) {
logger.error(String.format("There was an error converting the record metadata to a JSON string. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getOriginalMessage(), e);
}
return null;
return convertedString;
}
@Override
......@@ -36,17 +38,18 @@ public class RecordMetadataTypeConverter implements DynamoDBTypeConverter<String
public RecordMetadata unconvert(String recordMetadataString) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
RecordMetadata metadata;
try {
return objectMapper.readValue(recordMetadataString, new TypeReference<RecordMetadata>(){});
metadata = objectMapper.readValue(recordMetadataString, new TypeReference<RecordMetadata>(){});
} catch (JsonParseException e) {
logger.error(String.format("There was an error parsing the record metadata JSON string. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getOriginalMessage(), e);
} catch (JsonMappingException e) {
logger.error(String.format("There was an error mapping the record metadata JSON string. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getOriginalMessage(), e);
} catch (IOException e) {
logger.error(String.format("There was an IO exception while mapping the record metadata objects. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getLocalizedMessage(), e);
} catch (Exception e) {
logger.error(String.format("There was an unknown exception converting the record metadata. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getLocalizedMessage(), e);
}
return null;
return metadata;
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.opengroup.osdu.is.core.logging.JaxRsDpsLog;
import org.opengroup.osdu.is.core.util.AppException;
import javax.inject.Inject;
import java.io.IOException;
......@@ -19,28 +20,30 @@ public class SchemaExtTypeConverter implements DynamoDBTypeConverter<String, Map
@Override
public String convert(Map<String, Object> stringObjectMap) {
ObjectMapper objectMapper = new ObjectMapper();
String convertedString = null;
try {
return objectMapper.writeValueAsString(stringObjectMap);
convertedString = objectMapper.writeValueAsString(stringObjectMap);
} catch (JsonProcessingException e) {
logger.error(String.format("There was an error converting the schema to a JSON string. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getOriginalMessage(), e);
}
return null;
return convertedString;
}
@Override
public Map<String, Object> unconvert(String s) {
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> unconvertedMap;
try {
return objectMapper.readValue(s, new TypeReference<Map<String, Object>>(){});
unconvertedMap = objectMapper.readValue(s, new TypeReference<Map<String, Object>>(){});
} catch (JsonParseException e) {
logger.error(String.format("There was an error parsing the schema JSON string. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getOriginalMessage(), e);
} catch (JsonMappingException e) {
logger.error(String.format("There was an error mapping the schema JSON string. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getOriginalMessage(), e);
} catch (IOException e) {
logger.error(String.format("There was an IO exception while mapping the schema objects. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getLocalizedMessage(), e);
} catch (Exception e) {
logger.error(String.format("There was an unknown exception converting the schema. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getLocalizedMessage(), e);
}
return null;
return unconvertedMap;
}
}
......@@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.opengroup.osdu.core.api.storage.models.SchemaNode;
import org.opengroup.osdu.indexer.aws.model.SchemaItem;
import org.opengroup.osdu.is.core.logging.JaxRsDpsLog;
import org.opengroup.osdu.is.core.util.AppException;
import javax.inject.Inject;
import java.io.IOException;
......@@ -21,28 +22,30 @@ public class SchemaItemTypeConverter implements DynamoDBTypeConverter<String, Li
@Override
public String convert(List<SchemaItem> schemaNodes) {
ObjectMapper objectMapper = new ObjectMapper();
String convertedString;
try {
return objectMapper.writeValueAsString(schemaNodes);
convertedString = objectMapper.writeValueAsString(schemaNodes);
} catch (JsonProcessingException e) {
logger.error(String.format("There was an error converting the schema to a JSON string. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getOriginalMessage(), e);
}
return null;
return convertedString;
}
@Override
public List<SchemaItem> unconvert(String s) {
ObjectMapper objectMapper = new ObjectMapper();
List<SchemaItem> schemaItems;
try {
return objectMapper.readValue(s, new TypeReference<List<SchemaItem>>(){});
schemaItems = objectMapper.readValue(s, new TypeReference<List<SchemaItem>>(){});
} catch (JsonParseException e) {
logger.error(String.format("There was an error parsing the schema JSON string. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getOriginalMessage(), e);
} catch (JsonMappingException e) {
logger.error(String.format("There was an error mapping the schema JSON string. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getOriginalMessage(), e);
} catch (IOException e) {
logger.error(String.format("There was an IO exception while mapping the schema objects. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getLocalizedMessage(), e);
} catch (Exception e) {
logger.error(String.format("There was an unknown exception converting the schema. %s", e.getMessage()));
throw new AppException(e.hashCode(), e.getMessage(), e.getLocalizedMessage(), e);
}
return null;
return schemaItems;
}
}
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