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

Merge branch 'reference-fix-upsert' into 'master'

Fixed upsert method in reference module (GONRG-3573)

See merge request !171
parents dab22911 ad690ae2
No related branches found
No related tags found
1 merge request!171Fixed upsert method in reference module (GONRG-3573)
Pipeline #76090 failed
......@@ -35,6 +35,7 @@ import org.opengroup.osdu.legal.config.MongoDBConfigProperties;
import org.opengroup.osdu.legal.entity.LegalTagMongoEntity;
import org.opengroup.osdu.legal.provider.interfaces.ILegalTagRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
......@@ -59,7 +60,15 @@ public class MongoLegalTagRepository implements ILegalTagRepository {
MongoOperations ops = clientProvider.getOps(mongoDBConfigProperties.getMongoDbName());
LegalTagMongoEntity savedEntity = ops.save(convertFrom(legalTag), LEGAL_TAGS_ENTITYNAME);
LegalTagMongoEntity savedEntity = null;
try {
savedEntity = ops.insert(convertFrom(legalTag), LEGAL_TAGS_ENTITYNAME);
} catch (DuplicateKeyException ex){
throw new AppException(409, "Legal tag conflict", String.format(
"A LegalTag already exists for the given name %s. Can't create again. Id is %s",
legalTag.getName(), legalTag.getId()));
}
return savedEntity.getId();
}
......
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