use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class DefaultMetadataVersionService method getMetadataVersionsAsNode.
@Override
public RootNode getMetadataVersionsAsNode(List<MetadataVersion> versions) {
RootNode rootNode = NodeUtils.createRootNode("metadataversions");
CollectionNode collectionNode = new CollectionNode("metadataversions", true);
rootNode.addChild(collectionNode);
for (MetadataVersion version : versions) {
ComplexNode complexNode = new ComplexNode("");
complexNode.addChild(new SimpleNode("name", version.getName()));
complexNode.addChild(new SimpleNode("type", version.getType()));
complexNode.addChild(new SimpleNode("created", version.getCreated()));
complexNode.addChild(new SimpleNode("id", version.getUid()));
complexNode.addChild(new SimpleNode("importdate", version.getImportDate()));
complexNode.addChild(new SimpleNode("hashCode", version.getHashCode()));
collectionNode.addChild(complexNode);
}
return rootNode;
}
use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class DefaultMetadataVersionService method updateVersionName.
@Override
public void updateVersionName(int id, String name) {
MetadataVersion version = getVersionById(id);
if (version != null) {
version.setName(name);
updateVersion(version);
}
}
use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class MetadataSyncTask method runSyncTask.
public synchronized void runSyncTask(MetadataRetryContext context) throws MetadataSyncServiceException, DhisVersionMismatchException {
metadataSyncPreProcessor.setUp(context);
metadataSyncPreProcessor.handleAggregateDataPush(context);
metadataSyncPreProcessor.handleEventDataPush(context);
MetadataVersion metadataVersion = metadataSyncPreProcessor.handleCurrentMetadataVersion(context);
List<MetadataVersion> metadataVersionList = metadataSyncPreProcessor.handleMetadataVersionsList(context, metadataVersion);
if (metadataVersionList != null) {
for (MetadataVersion dataVersion : metadataVersionList) {
MetadataSyncParams syncParams = new MetadataSyncParams(new MetadataImportParams(), dataVersion);
boolean isSyncRequired = metadataSyncService.isSyncRequired(syncParams);
MetadataSyncSummary metadataSyncSummary = null;
if (isSyncRequired) {
metadataSyncSummary = handleMetadataSync(context, dataVersion);
} else {
metadataSyncPostProcessor.handleVersionAlreadyExists(context, dataVersion);
break;
}
boolean abortStatus = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, context, dataVersion);
if (abortStatus) {
break;
}
systemSettingManager.saveSystemSetting(SettingKey.LAST_SUCCESSFUL_METADATA_SYNC, dataVersion.getImportDate());
clearFailedVersionSettings();
}
}
log.info("Metadata sync cron job ended ");
}
use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class MetadataVersionDelegate method getMetaDataDifference.
public List<MetadataVersion> getMetaDataDifference(MetadataVersion metadataVersion) {
String url;
List<MetadataVersion> metadataVersions = new ArrayList<>();
if (metadataVersion == null) {
url = metadataSystemSettingService.getEntireVersionHistory();
} else {
url = metadataSystemSettingService.getMetaDataDifferenceURL(metadataVersion.getName());
}
DhisHttpResponse dhisHttpResponse = getDhisHttpResponse(url, VERSION_TIMEOUT);
if (isValidDhisHttpResponse(dhisHttpResponse)) {
try {
metadataVersions = renderService.fromMetadataVersion(new ByteArrayInputStream(dhisHttpResponse.getResponse().getBytes()), RenderFormat.JSON);
return metadataVersions;
} catch (IOException io) {
String message = "Exception occurred while trying to do JSON conversion. Caused by: " + io.getMessage();
log.error(message, io);
throw new MetadataVersionServiceException(message, io);
}
}
log.warn("Returning empty for the metadata versions difference");
return metadataVersions;
}
use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class DefaultMetadataSyncService method getParamsFromMap.
@Override
public MetadataSyncParams getParamsFromMap(Map<String, List<String>> parameters) {
List<String> versionName = getVersionsFromParams(parameters);
MetadataImportParams importParams = new MetadataImportParams();
importParams.setMetadataSyncImport(true);
MetadataSyncParams syncParams = new MetadataSyncParams();
syncParams.setImportParams(importParams);
String versionNameStr = versionName.get(0);
if (StringUtils.isNotEmpty(versionNameStr)) {
MetadataVersion version;
try {
version = metadataVersionDelegate.getRemoteMetadataVersion(versionNameStr);
} catch (MetadataVersionServiceException e) {
throw new MetadataSyncServiceException(e.getMessage(), e);
}
if (version == null) {
throw new MetadataSyncServiceException("The MetadataVersion could not be fetched from the remote server for the versionName: " + versionNameStr);
}
syncParams.setVersion(version);
}
syncParams.setParameters(parameters);
return syncParams;
}
Aggregations