Search in sources :

Example 46 with Metadata

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));
    }
}
Also used : ListGrid(org.hisp.dhis.system.grid.ListGrid) EventAnalyticsService(org.hisp.dhis.analytics.event.EventAnalyticsService) ValueType(org.hisp.dhis.common.ValueType) Autowired(org.springframework.beans.factory.annotation.Autowired) AnalyticsSecurityManager(org.hisp.dhis.analytics.AnalyticsSecurityManager) CombinationGenerator(org.hisp.dhis.common.CombinationGenerator) Future(java.util.concurrent.Future) Calendar(org.hisp.dhis.calendar.Calendar) Map(java.util.Map) IndicatorValue(org.hisp.dhis.indicator.IndicatorValue) ReportingRateMetric(org.hisp.dhis.common.ReportingRateMetric) Period(org.hisp.dhis.period.Period) ImmutableMap(com.google.common.collect.ImmutableMap) EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) ListUtils(org.hisp.dhis.commons.collection.ListUtils) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) Collection(java.util.Collection) IRT2D(org.hisp.dhis.reporttable.ReportTable.IRT2D) Set(java.util.Set) AnalyticsTableType(org.hisp.dhis.analytics.table.AnalyticsTableType) RawAnalyticsManager(org.hisp.dhis.analytics.RawAnalyticsManager) DimensionType(org.hisp.dhis.common.DimensionType) Collectors(java.util.stream.Collectors) DataValueSet(org.hisp.dhis.dxf2.datavalueset.DataValueSet) OrganisationUnit.getParentGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap) List(java.util.List) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalObject(org.hisp.dhis.common.DimensionalObject) ProcessingHint(org.hisp.dhis.analytics.ProcessingHint) LogFactory(org.apache.commons.logging.LogFactory) DimensionItem(org.hisp.dhis.analytics.DimensionItem) MathUtils(org.hisp.dhis.system.util.MathUtils) DimensionalObjectUtils.asTypedList(org.hisp.dhis.common.DimensionalObjectUtils.asTypedList) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ReportTable.addListIfEmpty(org.hisp.dhis.reporttable.ReportTable.addListIfEmpty) AnalyticsMetaDataKey(org.hisp.dhis.analytics.AnalyticsMetaDataKey) DataQueryService(org.hisp.dhis.analytics.DataQueryService) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) IdentifiableObjectUtils(org.hisp.dhis.common.IdentifiableObjectUtils) PeriodType.getPeriodTypeFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ExpressionService(org.hisp.dhis.expression.ExpressionService) Lists(com.google.common.collect.Lists) ReportTable(org.hisp.dhis.reporttable.ReportTable) GridHeader(org.hisp.dhis.common.GridHeader) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) Indicator(org.hisp.dhis.indicator.Indicator) User(org.hisp.dhis.user.User) DimensionalObjectUtils.getDimensionalItemIds(org.hisp.dhis.common.DimensionalObjectUtils.getDimensionalItemIds) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) OrganisationUnit.getParentNameGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap) DataDimensionItemType(org.hisp.dhis.common.DataDimensionItemType) DimensionalObjectUtils(org.hisp.dhis.common.DimensionalObjectUtils) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Timer(org.hisp.dhis.util.Timer) QueryPlanner(org.hisp.dhis.analytics.QueryPlanner) AggregationType(org.hisp.dhis.analytics.AggregationType) ConstantService(org.hisp.dhis.constant.ConstantService) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Grid(org.hisp.dhis.common.Grid) OutputFormat(org.hisp.dhis.analytics.OutputFormat) DebugUtils(org.hisp.dhis.commons.util.DebugUtils) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) SystemUtils(org.hisp.dhis.commons.util.SystemUtils) QueryPlannerParams(org.hisp.dhis.analytics.QueryPlannerParams) AnalyticsUtils(org.hisp.dhis.analytics.AnalyticsUtils) PeriodType(org.hisp.dhis.period.PeriodType) Log(org.apache.commons.logging.Log) IdentifiableObjectUtils.getLocalPeriodIdentifiers(org.hisp.dhis.common.IdentifiableObjectUtils.getLocalPeriodIdentifiers) SettingKey(org.hisp.dhis.setting.SettingKey) AnalyticsManager(org.hisp.dhis.analytics.AnalyticsManager) AnalyticsService(org.hisp.dhis.analytics.AnalyticsService) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) HashMap(java.util.HashMap) Calendar(org.hisp.dhis.calendar.Calendar) PeriodType.getPeriodTypeFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) List(java.util.List) DimensionalObjectUtils.asTypedList(org.hisp.dhis.common.DimensionalObjectUtils.asTypedList) ArrayList(java.util.ArrayList)

Example 47 with Metadata

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;
}
Also used : SystemTimer(org.hisp.dhis.commons.timer.SystemTimer) Timer(org.hisp.dhis.commons.timer.Timer) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) TypeReport(org.hisp.dhis.feedback.TypeReport) SystemTimer(org.hisp.dhis.commons.timer.SystemTimer) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 48 with Metadata

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");
}
Also used : MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) DhisHttpResponse(org.hisp.dhis.system.util.DhisHttpResponse) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 49 with Metadata

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());
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Pager(org.hisp.dhis.common.Pager) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 50 with Metadata

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");
    }
}
Also used : Video(com.brightcove.player.model.Video) Metadata(com.google.android.exoplayer2.metadata.Metadata) Event(com.brightcove.player.event.Event) EventListener(com.brightcove.player.event.EventListener) Id3Frame(com.google.android.exoplayer2.metadata.id3.Id3Frame) ExoPlayerVideoDisplayComponent(com.brightcove.player.display.ExoPlayerVideoDisplayComponent)

Aggregations

DhisSpringTest (org.hisp.dhis.DhisSpringTest)55 Test (org.junit.Test)55 List (java.util.List)46 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)46 ClassPathResource (org.springframework.core.io.ClassPathResource)42 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)37 DataElement (org.hisp.dhis.dataelement.DataElement)25 User (org.hisp.dhis.user.User)20 Metadata (com.google.android.exoplayer2.metadata.Metadata)19 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)19 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)19 DataSet (org.hisp.dhis.dataset.DataSet)15 ArrayList (java.util.ArrayList)14 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 IOException (java.io.IOException)10 Metadata (org.hisp.dhis.dxf2.metadata.Metadata)10 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)10 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)10 IntegrationTest (org.hisp.dhis.IntegrationTest)9