Skip to content
Snippets Groups Projects

fix(MetadataImportWorkFlowService): [AOU-1407] improve error message when an...

3 files
+ 61
9
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -9,12 +9,12 @@
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
@@ -129,6 +129,8 @@ public class MetadataImportWorkFlowService {
log.warn("Unable to import from pmid with the DOI '{}'", doi);
}
this.checkForIndirectDuplicate(Publication.ImportSource.DOI, doi, depositDoc);
if (isXmlFormat) {
return this.doiCrossrefImportService.transformDepositDocToMetadata(depositDoc);
} else {
@@ -145,11 +147,14 @@ public class MetadataImportWorkFlowService {
DepositDoc depositDoc = new DepositDoc();
depositDoc = this.pmidImportService.searchPmid(pmid, depositDoc);
String pmcId = depositDoc.getIdentifiers().getPmcid();
if (!StringTool.isNullOrEmpty(pmcId)) {
depositDoc = this.europePmcImportService.searchEuropePmcId(pmcId, depositDoc);
}
this.checkForIndirectDuplicate(Publication.ImportSource.PMID, pmid, depositDoc);
if (isXmlFormat) {
return this.pmidImportService.transformDepositDocToMetadata(depositDoc);
} else {
@@ -228,6 +233,9 @@ public class MetadataImportWorkFlowService {
this.messageService.get("deposit.error.identifiers.isbn.not_found", new Object[] { isbn }));
}
}
this.checkForIndirectDuplicate(Publication.ImportSource.ISBN, isbn, depositDoc);
if (isXmlFormat) {
return this.googleIsbnImportService.transformDepositDocToMetadata(depositDoc);
} else {
@@ -257,15 +265,57 @@ public class MetadataImportWorkFlowService {
message = this.messageService.get("deposit.error.identifiers.isbn.already_exists", new Object[] { value });
break;
}
this.throwExistingPublicationInfoExceptionIfExists(existingPublicationInfo, message);
}
}
private void checkForIndirectDuplicate(Publication.ImportSource source, String value, DepositDoc depositDoc) {
switch (source) {
case PMID:
this.checkIndirectDoi(depositDoc, value);
break;
case DOI:
this.checkIndirectPmid(depositDoc, value);
break;
case ISBN:
this.checkIndirectDoi(depositDoc, value);
this.checkIndirectPmid(depositDoc, value);
break;
}
}
private void checkIndirectDoi(DepositDoc depositDoc, String value) {
if (!StringTool.isNullOrEmpty(depositDoc.getIdentifiers().getDoi())) {
String doi = depositDoc.getIdentifiers().getDoi();
ExistingPublicationInfo existingPublicationInfo = this.duplicateService.getExistingPublicationInfoByDoi(doi);
if (existingPublicationInfo != null) {
this.throwExistingPublicationInfoExceptionIfExists(existingPublicationInfo,
this.messageService.get("deposit.error.identifiers.indirect_already_exists", new Object[] { value, "DOI", doi }));
}
}
}
private void checkIndirectPmid(DepositDoc depositDoc, String value) {
if (depositDoc.getIdentifiers().getPmid() != null) {
String pmid = depositDoc.getIdentifiers().getPmid().toString();
ExistingPublicationInfo existingPublicationInfo = this.duplicateService.getExistingPublicationInfoByPmid(pmid.toString());
if (existingPublicationInfo != null) {
final Map<Object, Object> params = new HashMap<>();
if (!StringTool.isNullOrEmpty(existingPublicationInfo.getUrl())) {
params.put("url", existingPublicationInfo.getUrl());
} else {
params.put("resId", existingPublicationInfo.getResId());
}
throw new AouRuntimeException(HttpStatus.BAD_REQUEST, message, ErrorCodes.IDENTIFIER_ALREADY_EXISTS.value(), params);
this.throwExistingPublicationInfoExceptionIfExists(existingPublicationInfo,
this.messageService.get("deposit.error.identifiers.indirect_already_exists", new Object[] { value, "PMID", pmid }));
}
}
}
private void throwExistingPublicationInfoExceptionIfExists(ExistingPublicationInfo existingPublicationInfo, String message) {
if (existingPublicationInfo != null) {
final Map<Object, Object> params = new HashMap<>();
if (!StringTool.isNullOrEmpty(existingPublicationInfo.getUrl())) {
params.put("url", existingPublicationInfo.getUrl());
} else {
params.put("resId", existingPublicationInfo.getResId());
}
throw new AouRuntimeException(HttpStatus.BAD_REQUEST, message, ErrorCodes.IDENTIFIER_ALREADY_EXISTS.value(), params);
}
}
Loading