use of org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException in project dhis2-core by dhis2.
the class MetadataSyncPreProcessor method handleMetadataVersionsList.
public List<MetadataVersion> handleMetadataVersionsList(MetadataRetryContext context, MetadataVersion metadataVersion) {
log.debug("Fetching the list of remote versions");
List<MetadataVersion> metadataVersionList = new ArrayList<>();
try {
metadataVersionList = metadataVersionDelegate.getMetaDataDifference(metadataVersion);
if (metadataVersion == null) {
log.info("There is no initial version in the system");
}
if (isRemoteVersionEmpty(metadataVersion, metadataVersionList)) {
log.info("There are no metadata versions created in the remote instance.");
return metadataVersionList;
}
if (isUsingLatestVersion(metadataVersion, metadataVersionList)) {
log.info("Your instance is already using the latest version:" + metadataVersion);
return metadataVersionList;
}
MetadataVersion latestVersion = getLatestVersion(metadataVersionList);
assert latestVersion != null;
systemSettingManager.saveSystemSetting(SettingKey.REMOTE_METADATA_VERSION, latestVersion.getName());
log.info("Remote system is at version: " + latestVersion.getName());
} catch (MetadataVersionServiceException e) {
String message = setVersionListErrorInfoInContext(context, metadataVersion, e);
throw new MetadataSyncServiceException(message, e);
} catch (Exception ex) {
if (ex instanceof MetadataSyncServiceException) {
log.error(ex.getMessage(), ex);
throw ex;
}
String message = setVersionListErrorInfoInContext(context, metadataVersion, ex);
log.error(message, ex);
throw new MetadataSyncServiceException(message, ex);
}
return metadataVersionList;
}
use of org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException in project dhis2-core by dhis2.
the class MetadataVersionNameGenerator method getNextVersionName.
public static String getNextVersionName(MetadataVersion version) {
if (version == null) {
return MetadataVersionService.METADATAVERSION_NAME_PREFIX + 1;
} else {
String[] versionNameSplit = version.getName().split("_");
String versionNameSuffix = versionNameSplit[1];
int n;
try {
n = Integer.parseInt(versionNameSuffix);
} catch (NumberFormatException nfe) {
String message = "Invalid version name found: " + versionNameSuffix;
log.error(message, nfe);
throw new MetadataVersionServiceException(message, nfe);
}
return MetadataVersionService.METADATAVERSION_NAME_PREFIX + (n + 1);
}
}
use of org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException in project dhis2-core by dhis2.
the class DefaultMetadataVersionService method createMetadataVersionInDataStore.
@Override
public void createMetadataVersionInDataStore(String versionName, String versionSnapshot) {
if (StringUtils.isEmpty(versionSnapshot)) {
throw new MetadataVersionServiceException("The Metadata Snapshot is null while trying to create a Metadata Version entry in DataStore.");
}
KeyJsonValue keyJsonValue = new KeyJsonValue();
keyJsonValue.setKey(versionName);
keyJsonValue.setNamespace(MetadataVersionService.METADATASTORE);
keyJsonValue.setValue(versionSnapshot);
try {
keyJsonValueService.addKeyJsonValue(keyJsonValue);
} catch (Exception ex) {
String message = "Exception occurred while saving the Metadata snapshot in Data Store" + ex.getMessage();
log.error(message, ex);
throw new MetadataVersionServiceException(message, ex);
}
}
use of org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException in project dhis2-core by dhis2.
the class MetadataVersionDelegate method getRemoteMetadataVersion.
public MetadataVersion getRemoteMetadataVersion(String versionName) {
String versionDetailsUrl = metadataSystemSettingService.getVersionDetailsUrl(versionName);
DhisHttpResponse dhisHttpResponse = getDhisHttpResponse(versionDetailsUrl, VERSION_TIMEOUT);
MetadataVersion dataVersion = null;
if (isValidDhisHttpResponse(dhisHttpResponse)) {
try {
dataVersion = renderService.fromJson(dhisHttpResponse.getResponse(), MetadataVersion.class);
} catch (Exception e) {
String message = "Exception occurred while trying to do JSON conversion for metadata version";
log.error(message, e);
throw new MetadataVersionServiceException(message, e);
}
}
return dataVersion;
}
use of org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException in project dhis2-core by dhis2.
the class MetadataVersionController method getMetaDataVersion.
//Gets the version by versionName or latest system version
@RequestMapping(value = MetadataVersionSchemaDescriptor.API_ENDPOINT, method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public MetadataVersion getMetaDataVersion(@RequestParam(value = "versionName", required = false) String versionName) throws MetadataVersionException, BadRequestException {
MetadataVersion versionToReturn = null;
boolean enabled = isMetadataVersioningEnabled();
try {
if (!enabled) {
throw new BadRequestException("Metadata versioning is not enabled for this instance.");
}
if (StringUtils.isNotEmpty(versionName)) {
versionToReturn = versionService.getVersionByName(versionName);
if (versionToReturn == null) {
throw new MetadataVersionException("No metadata version with name " + versionName + " exists. Please check again later.");
}
} else {
versionToReturn = versionService.getCurrentVersion();
if (versionToReturn == null) {
throw new MetadataVersionException("No metadata versions exist. Please check again later.");
}
}
return versionToReturn;
} catch (MetadataVersionServiceException ex) {
throw new MetadataVersionException("Exception occurred while getting metadata version." + (StringUtils.isNotEmpty(versionName) ? versionName : " ") + ex.getMessage(), ex);
}
}
Aggregations