use of org.hisp.dhis.common.BaseAnalyticalObject in project dhis2-core by dhis2.
the class FavoriteDataItemUpgrader method upgradeFavorites.
private void upgradeFavorites(Class<? extends BaseAnalyticalObject> favoriteClass, String favoriteTablename, Class<? extends IdentifiableObject> objectClass, String objectTablename) {
String linkTablename = favoriteTablename + "_" + objectTablename + "s";
String selectSql = "select " + favoriteTablename + "id, " + objectTablename + "id from " + linkTablename + " " + "order by " + favoriteTablename + "id, sort_order";
SqlRowSet rs = jdbcTemplate.queryForRowSet(selectSql);
while (rs.next()) {
int rtId = rs.getInt(1);
int obId = rs.getInt(2);
BaseAnalyticalObject favorite = idObjectManager.get(favoriteClass, rtId);
DimensionalItemObject object = (DimensionalItemObject) idObjectManager.get(objectClass, obId);
DataDimensionItem item = DataDimensionItem.create(object);
favorite.getDataDimensionItems().add(item);
idObjectManager.update(favorite);
log.debug("Upgraded " + favoriteTablename + " " + favorite.getUid() + " for " + objectTablename + " " + object.getUid());
}
String dropSql = "drop table " + linkTablename;
jdbcTemplate.update(dropSql);
log.info("Update done, dropped table " + linkTablename);
}
use of org.hisp.dhis.common.BaseAnalyticalObject in project dhis2-core by dhis2.
the class AnalyticalObjectObjectBundleHook method preUpdate.
@Override
public void preUpdate(IdentifiableObject object, IdentifiableObject persistedObject, ObjectBundle bundle) {
if (!AnalyticalObject.class.isInstance(object))
return;
BaseAnalyticalObject analyticalObject = (BaseAnalyticalObject) object;
Schema schema = schemaService.getDynamicSchema(analyticalObject.getClass());
Session session = sessionFactory.getCurrentSession();
handleDataDimensionItems(session, schema, analyticalObject, bundle);
handleCategoryDimensions(session, schema, analyticalObject, bundle);
handleDataElementDimensions(session, schema, analyticalObject, bundle);
handleAttributeDimensions(session, schema, analyticalObject, bundle);
handleProgramIndicatorDimensions(session, schema, analyticalObject, bundle);
}
use of org.hisp.dhis.common.BaseAnalyticalObject in project dhis2-core by dhis2.
the class GeoToolsMapGenerationService method generateMapImageForUser.
@Override
public BufferedImage generateMapImageForUser(Map map, Date date, OrganisationUnit unit, Integer width, Integer height, User user) {
Assert.isTrue(map != null, "Map cannot be null");
if (width == null && height == null) {
width = MapUtils.DEFAULT_MAP_WIDTH;
}
InternalMap internalMap = new InternalMap();
List<MapView> mapViews = new ArrayList<>(map.getMapViews());
Collections.reverse(mapViews);
for (MapView mapView : mapViews) {
InternalMapLayer mapLayer = getSingleInternalMapLayer(mapView, user, date);
if (mapLayer != null) {
internalMap.getLayers().add(mapLayer);
}
}
if (internalMap.getLayers().isEmpty()) {
return null;
}
InternalMapLayer dataLayer = internalMap.getFirstDataLayer();
BufferedImage mapImage = MapUtils.render(internalMap, width, height);
if (dataLayer == null) {
mapViews.forEach(BaseAnalyticalObject::clearTransientState);
return mapImage;
} else {
LegendSet legendSet = new LegendSet(dataLayer);
BufferedImage legendImage = legendSet.render(i18nManager.getI18nFormat());
BufferedImage titleImage = MapUtils.renderTitle(map.getName(), getImageWidth(legendImage, mapImage));
mapViews.forEach(BaseAnalyticalObject::clearTransientState);
return combineLegendAndMapImages(titleImage, legendImage, mapImage);
}
}
use of org.hisp.dhis.common.BaseAnalyticalObject in project dhis2-core by dhis2.
the class AnalyticalObjectObjectBundleHook method preCreate.
@Override
public void preCreate(IdentifiableObject object, ObjectBundle bundle) {
if (!AnalyticalObject.class.isInstance(object))
return;
BaseAnalyticalObject analyticalObject = (BaseAnalyticalObject) object;
Schema schema = schemaService.getDynamicSchema(analyticalObject.getClass());
Session session = sessionFactory.getCurrentSession();
handleDataDimensionItems(session, schema, analyticalObject, bundle);
handleCategoryDimensions(session, schema, analyticalObject, bundle);
handleDataElementDimensions(session, schema, analyticalObject, bundle);
handleAttributeDimensions(session, schema, analyticalObject, bundle);
handleProgramIndicatorDimensions(session, schema, analyticalObject, bundle);
}
use of org.hisp.dhis.common.BaseAnalyticalObject in project dhis2-core by dhis2.
the class DefaultPreheatService method collectReferences.
@SuppressWarnings("unchecked")
private Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Set<String>>> collectReferences(Map<Class<?>, List<?>> objects) {
Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Set<String>>> map = new HashMap<>();
map.put(PreheatIdentifier.UID, new HashMap<>());
map.put(PreheatIdentifier.CODE, new HashMap<>());
Map<Class<? extends IdentifiableObject>, Set<String>> uidMap = map.get(PreheatIdentifier.UID);
Map<Class<? extends IdentifiableObject>, Set<String>> codeMap = map.get(PreheatIdentifier.CODE);
if (objects.isEmpty()) {
return map;
}
Map<Class<?>, List<?>> targets = new HashMap<>();
// clone objects list, we don't want to modify it
targets.putAll(objects);
collectScanTargets(targets);
for (Class<?> klass : targets.keySet()) {
Schema schema = schemaService.getDynamicSchema(klass);
List<Property> referenceProperties = schema.getProperties().stream().filter(p -> p.isPersisted() && p.isOwner() && (PropertyType.REFERENCE == p.getPropertyType() || PropertyType.REFERENCE == p.getItemPropertyType())).collect(Collectors.toList());
for (Object object : targets.get(klass)) {
if (schema.isIdentifiableObject()) {
IdentifiableObject identifiableObject = (IdentifiableObject) object;
identifiableObject.getAttributeValues().forEach(av -> addIdentifiers(map, av.getAttribute()));
identifiableObject.getUserGroupAccesses().forEach(uga -> addIdentifiers(map, uga.getUserGroup()));
identifiableObject.getUserAccesses().forEach(ua -> addIdentifiers(map, ua.getUser()));
addIdentifiers(map, identifiableObject);
}
referenceProperties.forEach(p -> {
if (!p.isCollection()) {
Class<? extends IdentifiableObject> itemKlass = (Class<? extends IdentifiableObject>) p.getKlass();
if (!uidMap.containsKey(itemKlass))
uidMap.put(itemKlass, new HashSet<>());
if (!codeMap.containsKey(itemKlass))
codeMap.put(itemKlass, new HashSet<>());
Object reference = ReflectionUtils.invokeMethod(object, p.getGetterMethod());
if (reference != null) {
IdentifiableObject identifiableObject = (IdentifiableObject) reference;
addIdentifiers(map, identifiableObject);
}
} else {
Collection<IdentifiableObject> reference = ReflectionUtils.invokeMethod(object, p.getGetterMethod());
reference.forEach(identifiableObject -> addIdentifiers(map, identifiableObject));
if (DataElementOperand.class.isAssignableFrom(p.getItemKlass())) {
CollectionUtils.nullSafeForEach(reference, identifiableObject -> {
DataElementOperand dataElementOperand = (DataElementOperand) identifiableObject;
addIdentifiers(map, dataElementOperand.getDataElement());
addIdentifiers(map, dataElementOperand.getCategoryOptionCombo());
});
}
}
});
if (AnalyticalObject.class.isInstance(object)) {
BaseAnalyticalObject analyticalObject = (BaseAnalyticalObject) object;
List<DataDimensionItem> dataDimensionItems = analyticalObject.getDataDimensionItems();
List<CategoryDimension> categoryDimensions = analyticalObject.getCategoryDimensions();
List<TrackedEntityDataElementDimension> trackedEntityDataElementDimensions = analyticalObject.getDataElementDimensions();
List<TrackedEntityAttributeDimension> attributeDimensions = analyticalObject.getAttributeDimensions();
List<TrackedEntityProgramIndicatorDimension> programIndicatorDimensions = analyticalObject.getProgramIndicatorDimensions();
CollectionUtils.nullSafeForEach(dataDimensionItems, dataDimensionItem -> {
addIdentifiers(map, dataDimensionItem.getDimensionalItemObject());
if (dataDimensionItem.getDataElementOperand() != null) {
addIdentifiers(map, dataDimensionItem.getDataElementOperand().getDataElement());
addIdentifiers(map, dataDimensionItem.getDataElementOperand().getCategoryOptionCombo());
}
if (dataDimensionItem.getReportingRate() != null) {
addIdentifiers(map, dataDimensionItem.getReportingRate().getDataSet());
}
});
CollectionUtils.nullSafeForEach(categoryDimensions, categoryDimension -> {
addIdentifiers(map, categoryDimension.getDimension());
categoryDimension.getItems().forEach(item -> addIdentifiers(map, item));
});
CollectionUtils.nullSafeForEach(trackedEntityDataElementDimensions, trackedEntityDataElementDimension -> {
addIdentifiers(map, trackedEntityDataElementDimension.getDataElement());
addIdentifiers(map, trackedEntityDataElementDimension.getLegendSet());
});
CollectionUtils.nullSafeForEach(attributeDimensions, trackedEntityAttributeDimension -> {
addIdentifiers(map, trackedEntityAttributeDimension.getAttribute());
addIdentifiers(map, trackedEntityAttributeDimension.getLegendSet());
});
CollectionUtils.nullSafeForEach(programIndicatorDimensions, programIndicatorDimension -> {
addIdentifiers(map, programIndicatorDimension.getProgramIndicator());
addIdentifiers(map, programIndicatorDimension.getLegendSet());
});
}
}
}
cleanEmptyEntries(uidMap);
cleanEmptyEntries(codeMap);
return map;
}
Aggregations