use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class DefaultAnalyticsService method addMetaData.
/**
* Adds meta data values to the given grid based on the given data query
* parameters.
*
* @param params the {@link DataQueryParams}.
* @param grid the grid.
*/
private void addMetaData(DataQueryParams params, Grid grid) {
if (!params.isSkipMeta()) {
Map<String, Object> metaData = new HashMap<>();
Map<String, Object> internalMetaData = new HashMap<>();
// -----------------------------------------------------------------
// Items / names element
// -----------------------------------------------------------------
Map<String, String> cocNameMap = AnalyticsUtils.getCocNameMap(params);
if (params.getApiVersion().ge(DhisApiVersion.V26)) {
metaData.put(AnalyticsMetaDataKey.ITEMS.getKey(), AnalyticsUtils.getDimensionMetadataItemMap(params));
} else {
Map<String, String> uidNameMap = AnalyticsUtils.getDimensionItemNameMap(params);
uidNameMap.putAll(cocNameMap);
uidNameMap.put(DATA_X_DIM_ID, DISPLAY_NAME_DATA_X);
metaData.put(AnalyticsMetaDataKey.NAMES.getKey(), uidNameMap);
}
// -----------------------------------------------------------------
// Item order elements
// -----------------------------------------------------------------
Map<String, Object> dimensionItems = new HashMap<>();
Calendar calendar = PeriodType.getCalendar();
List<String> periodUids = calendar.isIso8601() ? getDimensionalItemIds(params.getDimensionOrFilterItems(PERIOD_DIM_ID)) : getLocalPeriodIdentifiers(params.getDimensionOrFilterItems(PERIOD_DIM_ID), calendar);
dimensionItems.put(PERIOD_DIM_ID, periodUids);
dimensionItems.put(CATEGORYOPTIONCOMBO_DIM_ID, cocNameMap.keySet());
for (DimensionalObject dim : params.getDimensionsAndFilters()) {
if (!dimensionItems.keySet().contains(dim.getDimension())) {
dimensionItems.put(dim.getDimension(), getDimensionalItemIds(dim.getItems()));
}
}
if (params.getApiVersion().ge(DhisApiVersion.V26)) {
metaData.put(AnalyticsMetaDataKey.DIMENSIONS.getKey(), dimensionItems);
} else {
metaData.putAll(dimensionItems);
}
// -----------------------------------------------------------------
// Organisation unit hierarchy
// -----------------------------------------------------------------
User user = securityManager.getCurrentUser(params);
List<OrganisationUnit> organisationUnits = asTypedList(params.getDimensionOrFilterItems(ORGUNIT_DIM_ID));
Collection<OrganisationUnit> roots = user != null ? user.getOrganisationUnits() : null;
if (params.isHierarchyMeta()) {
metaData.put(AnalyticsMetaDataKey.ORG_UNIT_HIERARCHY.getKey(), getParentGraphMap(organisationUnits, roots));
}
if (params.isShowHierarchy()) {
Map<Object, List<?>> ancestorMap = organisationUnits.stream().collect(Collectors.toMap(OrganisationUnit::getUid, ou -> ou.getAncestorNames(roots, true)));
internalMetaData.put(AnalyticsMetaDataKey.ORG_UNIT_ANCESTORS.getKey(), ancestorMap);
metaData.put(AnalyticsMetaDataKey.ORG_UNIT_NAME_HIERARCHY.getKey(), getParentNameGraphMap(organisationUnits, roots, true));
}
grid.setMetaData(ImmutableMap.copyOf(metaData));
grid.setInternalMetaData(ImmutableMap.copyOf(internalMetaData));
}
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class DefaultObjectBundleValidationService method validate.
@Override
public ObjectBundleValidationReport validate(ObjectBundle bundle) {
Timer timer = new SystemTimer().start();
ObjectBundleValidationReport validation = new ObjectBundleValidationReport();
if ((bundle.getUser() == null || bundle.getUser().isSuper()) && bundle.isSkipValidation()) {
log.warn("Skipping validation for metadata import by user '" + bundle.getUsername() + "'. Not recommended.");
return validation;
}
List<Class<? extends IdentifiableObject>> klasses = getSortedClasses(bundle);
for (Class<? extends IdentifiableObject> klass : klasses) {
TypeReport typeReport = new TypeReport(klass);
List<IdentifiableObject> nonPersistedObjects = bundle.getObjects(klass, false);
List<IdentifiableObject> persistedObjects = bundle.getObjects(klass, true);
List<IdentifiableObject> allObjects = bundle.getObjectMap().get(klass);
handleDefaults(nonPersistedObjects);
handleDefaults(persistedObjects);
typeReport.merge(checkDuplicateIds(klass, persistedObjects, nonPersistedObjects, bundle.getPreheat(), bundle.getPreheatIdentifier()));
if (bundle.getImportMode().isCreateAndUpdate()) {
typeReport.merge(runValidationHooks(klass, nonPersistedObjects, bundle));
typeReport.merge(runValidationHooks(klass, persistedObjects, bundle));
typeReport.merge(validateSecurity(klass, nonPersistedObjects, bundle, ImportStrategy.CREATE));
typeReport.merge(validateSecurity(klass, persistedObjects, bundle, ImportStrategy.UPDATE));
typeReport.merge(validateBySchemas(klass, nonPersistedObjects, bundle));
typeReport.merge(validateBySchemas(klass, persistedObjects, bundle));
typeReport.merge(checkUniqueness(klass, nonPersistedObjects, bundle.getPreheat(), bundle.getPreheatIdentifier()));
typeReport.merge(checkUniqueness(klass, persistedObjects, bundle.getPreheat(), bundle.getPreheatIdentifier()));
typeReport.merge(checkMandatoryAttributes(klass, nonPersistedObjects, bundle.getPreheat(), bundle.getPreheatIdentifier()));
typeReport.merge(checkMandatoryAttributes(klass, persistedObjects, bundle.getPreheat(), bundle.getPreheatIdentifier()));
typeReport.merge(checkUniqueAttributes(klass, nonPersistedObjects, bundle.getPreheat(), bundle.getPreheatIdentifier()));
typeReport.merge(checkUniqueAttributes(klass, persistedObjects, bundle.getPreheat(), bundle.getPreheatIdentifier()));
TypeReport checkReferences = checkReferences(klass, allObjects, bundle.getPreheat(), bundle.getPreheatIdentifier(), bundle.isSkipSharing());
if (!checkReferences.getErrorReports().isEmpty() && AtomicMode.ALL == bundle.getAtomicMode()) {
typeReport.getStats().incIgnored();
}
typeReport.getStats().incCreated(nonPersistedObjects.size());
typeReport.getStats().incUpdated(persistedObjects.size());
typeReport.merge(checkReferences);
} else if (bundle.getImportMode().isCreate()) {
typeReport.merge(runValidationHooks(klass, nonPersistedObjects, bundle));
typeReport.merge(validateSecurity(klass, nonPersistedObjects, bundle, ImportStrategy.CREATE));
typeReport.merge(validateForCreate(klass, persistedObjects, bundle));
typeReport.merge(validateBySchemas(klass, nonPersistedObjects, bundle));
typeReport.merge(checkUniqueness(klass, nonPersistedObjects, bundle.getPreheat(), bundle.getPreheatIdentifier()));
typeReport.merge(checkMandatoryAttributes(klass, nonPersistedObjects, bundle.getPreheat(), bundle.getPreheatIdentifier()));
typeReport.merge(checkUniqueAttributes(klass, nonPersistedObjects, bundle.getPreheat(), bundle.getPreheatIdentifier()));
TypeReport checkReferences = checkReferences(klass, allObjects, bundle.getPreheat(), bundle.getPreheatIdentifier(), bundle.isSkipSharing());
if (!checkReferences.getErrorReports().isEmpty() && AtomicMode.ALL == bundle.getAtomicMode()) {
typeReport.getStats().incIgnored();
}
typeReport.getStats().incCreated(nonPersistedObjects.size());
typeReport.merge(checkReferences);
} else if (bundle.getImportMode().isUpdate()) {
typeReport.merge(runValidationHooks(klass, persistedObjects, bundle));
typeReport.merge(validateSecurity(klass, persistedObjects, bundle, ImportStrategy.UPDATE));
typeReport.merge(validateForUpdate(klass, nonPersistedObjects, bundle));
typeReport.merge(validateBySchemas(klass, persistedObjects, bundle));
typeReport.merge(checkUniqueness(klass, persistedObjects, bundle.getPreheat(), bundle.getPreheatIdentifier()));
typeReport.merge(checkMandatoryAttributes(klass, persistedObjects, bundle.getPreheat(), bundle.getPreheatIdentifier()));
typeReport.merge(checkUniqueAttributes(klass, persistedObjects, bundle.getPreheat(), bundle.getPreheatIdentifier()));
TypeReport checkReferences = checkReferences(klass, allObjects, bundle.getPreheat(), bundle.getPreheatIdentifier(), bundle.isSkipSharing());
if (!checkReferences.getErrorReports().isEmpty() && AtomicMode.ALL == bundle.getAtomicMode()) {
typeReport.getStats().incIgnored();
}
typeReport.getStats().incUpdated(persistedObjects.size());
typeReport.merge(checkReferences);
} else if (bundle.getImportMode().isDelete()) {
typeReport.merge(validateSecurity(klass, persistedObjects, bundle, ImportStrategy.DELETE));
typeReport.merge(validateForDelete(klass, nonPersistedObjects, bundle));
typeReport.getStats().incDeleted(persistedObjects.size());
}
validation.addTypeReport(typeReport);
}
validateAtomicity(bundle, validation);
bundle.setObjectBundleStatus(ObjectBundleStatus.VALIDATED);
log.info("(" + bundle.getUsername() + ") Import:Validation took " + timer.toString());
return validation;
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class MetadataVersionDelegateTest method testShouldThrowExceptionWhenRenderServiceThrowsException.
@Test
public void testShouldThrowExceptionWhenRenderServiceThrowsException() throws Exception {
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "testMessage", null);
DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.OK.value());
when(metadataSystemSettingService.getVersionDetailsUrl("testVersion")).thenReturn(versionUrl);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
PowerMockito.when(HttpUtils.httpGET(versionUrl, true, username, password, null, VERSION_TIMEOUT, true)).thenReturn(dhisHttpResponse);
when(renderService.fromJson(response, MetadataVersion.class)).thenThrow(new MetadataVersionServiceException(""));
expectedException.expect(MetadataVersionServiceException.class);
expectedException.expectMessage("Exception occurred while trying to do JSON conversion for metadata version");
metadataVersionDelegate.getRemoteMetadataVersion("testVersion");
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class DataElementGroupController method getOperands.
@RequestMapping(value = "/{uid}/operands", method = RequestMethod.GET)
public String getOperands(@PathVariable("uid") String uid, @RequestParam Map<String, String> parameters, Model model, TranslateParams translateParams, HttpServletRequest request, HttpServletResponse response) throws Exception {
WebOptions options = new WebOptions(parameters);
setUserContext(translateParams);
List<DataElementGroup> dataElementGroups = getEntity(uid, NO_WEB_OPTIONS);
if (dataElementGroups.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound("DataElementGroup not found for uid: " + uid));
}
WebMetadata metadata = new WebMetadata();
List<DataElementOperand> dataElementOperands = Lists.newArrayList(dataElementCategoryService.getOperands(dataElementGroups.get(0).getMembers()));
Collections.sort(dataElementOperands);
metadata.setDataElementOperands(dataElementOperands);
if (options.hasPaging()) {
Pager pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
metadata.setPager(pager);
dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
}
metadata.setDataElementOperands(dataElementOperands);
linkService.generateLinks(metadata, false);
model.addAttribute("model", metadata);
model.addAttribute("viewClass", options.getViewClass("basic"));
return StringUtils.uncapitalize(getEntitySimpleName());
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project android-player-samples by BrightcoveOS.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
brightcoveVideoView.getEventEmitter().on(EventType.DID_SET_SOURCE, new EventListener() {
@Override
public void processEvent(Event event) {
ExoPlayerVideoDisplayComponent exoPlayerVideoDisplayComponent = (ExoPlayerVideoDisplayComponent) brightcoveVideoView.getVideoDisplay();
exoPlayerVideoDisplayComponent.setMetadataListener(new ExoPlayerVideoDisplayComponent.MetadataListener() {
@Override
public void onMetadata(Metadata metadata) {
for (int i = 0; i < metadata.length(); i++) {
Metadata.Entry entry = metadata.get(i);
if (entry instanceof Id3Frame) {
Id3Frame id3Frame = (Id3Frame) entry;
Log.v(TAG, "id3 Frame id: " + id3Frame.id);
}
}
}
});
}
});
Video video = Video.createVideo("https://s3.amazonaws.com/as-zencoder/hls-timed-metadata/test.m3u8", DeliveryType.HLS);
video.getProperties().put(Video.Fields.PUBLISHER_ID, "5420904993001");
brightcoveVideoView.add(video);
brightcoveVideoView.start();
// Log whether or not instance state in non-null.
if (savedInstanceState != null) {
Log.v(TAG, "Restoring saved position");
} else {
Log.v(TAG, "No saved state");
}
}
Aggregations