Search in sources :

Example 1 with AttributeGroupDTO

use of org.activityinfo.shared.dto.AttributeGroupDTO in project activityinfo by bedatadriven.

the class ColumnBindingFactory method forActivity.

public static List<ColumnBinding> forActivity(ActivityDTO activity) {
    List<ColumnBinding> bindings = Lists.newArrayList();
    bindings.add(Ignore.INSTANCE);
    bindings.add(new DateBinding());
    for (AdminLevelDTO level : activity.getAdminLevels()) {
        bindings.add(new AdminBinding(level));
    }
    if (!activity.getLocationType().isAdminLevel()) {
        bindings.add(new LocationNameBinding(activity.getLocationType()));
    }
    for (IndicatorDTO indicator : activity.getIndicators()) {
        bindings.add(new IndicatorBinding(indicator));
    }
    for (AttributeGroupDTO attributeGroup : activity.getAttributeGroups()) {
        bindings.add(new AttributeBinding(attributeGroup));
    }
    bindings.add(new CommentsBinding());
    return bindings;
}
Also used : IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) AdminLevelDTO(org.activityinfo.shared.dto.AdminLevelDTO)

Example 2 with AttributeGroupDTO

use of org.activityinfo.shared.dto.AttributeGroupDTO in project activityinfo by bedatadriven.

the class DesignView method initNewMenu.

protected void initNewMenu(Menu menu, SelectionListener<MenuEvent> listener) {
    MenuItem newActivity = new MenuItem(I18N.CONSTANTS.newActivity(), IconImageBundle.ICONS.activity(), listener);
    newActivity.setItemId("Activity");
    menu.add(newActivity);
    final MenuItem newAttributeGroup = new MenuItem(I18N.CONSTANTS.newAttributeGroup(), IconImageBundle.ICONS.attributeGroup(), listener);
    newAttributeGroup.setItemId("AttributeGroup");
    menu.add(newAttributeGroup);
    final MenuItem newAttribute = new MenuItem(I18N.CONSTANTS.newAttribute(), IconImageBundle.ICONS.attribute(), listener);
    newAttribute.setItemId("Attribute");
    menu.add(newAttribute);
    final MenuItem newIndicator = new MenuItem(I18N.CONSTANTS.newIndicator(), IconImageBundle.ICONS.indicator(), listener);
    newIndicator.setItemId("Indicator");
    menu.add(newIndicator);
    menu.addListener(Events.BeforeShow, new Listener<BaseEvent>() {

        @Override
        public void handleEvent(BaseEvent be) {
            ModelData sel = getSelection();
            newAttributeGroup.setEnabled(sel != null);
            newAttribute.setEnabled(sel instanceof AttributeGroupDTO || sel instanceof AttributeDTO);
            newIndicator.setEnabled(sel != null);
        }
    });
}
Also used : AttributeDTO(org.activityinfo.shared.dto.AttributeDTO) ModelData(com.extjs.gxt.ui.client.data.ModelData) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) BaseEvent(com.extjs.gxt.ui.client.event.BaseEvent) SeparatorMenuItem(com.extjs.gxt.ui.client.widget.menu.SeparatorMenuItem) MenuItem(com.extjs.gxt.ui.client.widget.menu.MenuItem)

Example 3 with AttributeGroupDTO

use of org.activityinfo.shared.dto.AttributeGroupDTO in project activityinfo by bedatadriven.

the class SiteExporter method createHeaders.

private void createHeaders(ActivityDTO activity, HSSFSheet sheet) {
    // / The HEADER rows
    Row headerRow1 = sheet.createRow(0);
    Row headerRow2 = sheet.createRow(1);
    headerRow2.setHeightInPoints(HEADER_CELL_HEIGHT);
    // Create a title cell with the complete database + activity name
    Cell titleCell = headerRow1.createCell(0);
    titleCell.setCellValue(creationHelper.createRichTextString(activity.getDatabase().getName() + " - " + activity.getName()));
    titleCell.setCellStyle(titleStyle);
    int column = 0;
    createHeaderCell(headerRow2, column++, "Date1", CellStyle.ALIGN_RIGHT);
    createHeaderCell(headerRow2, column++, "Date2", CellStyle.ALIGN_RIGHT);
    createHeaderCell(headerRow2, column, "Partner");
    sheet.setColumnWidth(column, characters(PARTNER_COLUMN_WIDTH));
    column++;
    createHeaderCell(headerRow2, column, activity.getLocationType().getName());
    sheet.setColumnWidth(column, characters(LOCATION_COLUMN_WIDTH));
    column++;
    createHeaderCell(headerRow2, column++, "Axe");
    indicators = new ArrayList<Integer>(activity.getIndicators().size());
    if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
        for (IndicatorGroup group : activity.groupIndicators()) {
            if (group.getName() != null) {
                // create a merged cell on the top row spanning all members
                // of the group
                createHeaderCell(headerRow1, column, group.getName());
                sheet.addMergedRegion(new CellRangeAddress(0, 0, column, column + group.getIndicators().size() - 1));
            }
            for (IndicatorDTO indicator : group.getIndicators()) {
                indicators.add(indicator.getId());
                createHeaderCell(headerRow2, column, indicator.getName(), indicatorHeaderStyle);
                sheet.setColumnWidth(column, characters(INDICATOR_COLUMN_WIDTH));
                column++;
            }
        }
    }
    attributes = new ArrayList<Integer>();
    for (AttributeGroupDTO group : activity.getAttributeGroups()) {
        if (group.getAttributes().size() != 0) {
            createHeaderCell(headerRow1, column, group.getName(), CellStyle.ALIGN_CENTER);
            sheet.addMergedRegion(new CellRangeAddress(0, 0, column, column + group.getAttributes().size() - 1));
            for (AttributeDTO attrib : group.getAttributes()) {
                attributes.add(attrib.getId());
                createHeaderCell(headerRow2, column, attrib.getName(), attribHeaderStyle);
                sheet.setColumnWidth(column, characters(ATTRIBUTE_COLUMN_WIDTH));
                column++;
            }
        }
    }
    levels = new ArrayList<Integer>();
    for (AdminLevelDTO level : activity.getAdminLevels()) {
        createHeaderCell(headerRow2, column++, "Code " + level.getName());
        createHeaderCell(headerRow2, column++, level.getName());
        levels.add(level.getId());
    }
    int latColumn = column++;
    int lngColumn = column++;
    createHeaderCell(headerRow2, latColumn, I18N.CONSTANTS.longitude(), CellStyle.ALIGN_RIGHT);
    createHeaderCell(headerRow2, lngColumn, I18N.CONSTANTS.latitude(), CellStyle.ALIGN_RIGHT);
    sheet.setColumnWidth(lngColumn, characters(COORD_COLUMN_WIDTH));
    sheet.setColumnWidth(latColumn, characters(COORD_COLUMN_WIDTH));
    createHeaderCell(headerRow2, column++, I18N.CONSTANTS.comments());
}
Also used : AttributeDTO(org.activityinfo.shared.dto.AttributeDTO) IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) IndicatorGroup(org.activityinfo.shared.dto.IndicatorGroup) AdminLevelDTO(org.activityinfo.shared.dto.AdminLevelDTO) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Cell(org.apache.poi.ss.usermodel.Cell)

Example 4 with AttributeGroupDTO

use of org.activityinfo.shared.dto.AttributeGroupDTO in project activityinfo by bedatadriven.

the class FormSubmissionResource method createSite.

private void createSite(SiteFormData data, SchemaDTO schemaDTO, ActivityDTO activity) {
    final SiteDTO site = new SiteDTO();
    site.setId(new KeyGenerator().generateInt());
    site.setActivityId(data.getActivity());
    if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
        site.setReportingPeriodId(new KeyGenerator().generateInt());
    }
    // set activitymodel
    if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
        site.setDate1(data.getDate1());
        site.setDate2(data.getDate2());
    }
    site.setPartner(schemaDTO.getPartnerById(data.getPartner()));
    // set comments
    site.setComments(data.getComments());
    // set attributes
    for (FormAttributeGroup formAttributeGroup : data.getAttributegroups()) {
        AttributeGroupDTO attributeGroup = activity.getAttributeGroupById(formAttributeGroup.getId());
        for (Integer attributeId : attributeGroup.getAttributeIds()) {
            site.setAttributeValue(attributeId, formAttributeGroup.isSelected(attributeId));
        }
    }
    // set indicators
    if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
        for (FormIndicator formIndicator : data.getIndicators()) {
            site.setIndicatorValue(formIndicator.getId(), formIndicator.getDoubleValue());
        }
    }
    // create command(s)
    CreateSite cmd = new CreateSite(site);
    cmd.setNestedCommand(createCreateLocationCommand(data, schemaDTO, activity));
    // save
    CreateResult createResult = dispatcher.execute(cmd);
    // create sitehistory entry
    siteHistoryProcessor.process(cmd, getUser().getId(), createResult.getNewId());
}
Also used : FormAttributeGroup(org.activityinfo.server.endpoint.odk.SiteFormData.FormAttributeGroup) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) FormIndicator(org.activityinfo.server.endpoint.odk.SiteFormData.FormIndicator) CreateResult(org.activityinfo.shared.command.result.CreateResult) SiteDTO(org.activityinfo.shared.dto.SiteDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) CreateSite(org.activityinfo.shared.command.CreateSite)

Example 5 with AttributeGroupDTO

use of org.activityinfo.shared.dto.AttributeGroupDTO in project activityinfo by bedatadriven.

the class GetAttributeGroupsDimensionHandler method execute.

@Override
public void execute(GetAttributeGroupsDimension cmd, final ExecutionContext context, final AsyncCallback<AttributeGroupResult> callback) {
    // if the filter doesn't contain any activity, database or indicator values, just return an empty list
    if (!cmd.getFilter().isRestricted(DimensionType.Database) && !cmd.getFilter().isRestricted(DimensionType.Activity) && !cmd.getFilter().isRestricted(DimensionType.Indicator)) {
        callback.onSuccess(new AttributeGroupResult());
        return;
    }
    final Dimension dimension = new Dimension(DimensionType.AttributeGroup);
    final PivotSites query = new PivotSites();
    query.setFilter(cmd.getFilter());
    query.setDimensions(dimension);
    query.setValueType(ValueType.DIMENSION);
    context.execute(query, new AsyncCallback<PivotSites.PivotResult>() {

        @Override
        public void onSuccess(PivotSites.PivotResult result) {
            final List<AttributeGroupDTO> list = new ArrayList<AttributeGroupDTO>();
            // populate the resultlist
            for (Bucket bucket : result.getBuckets()) {
                EntityCategory category = (EntityCategory) bucket.getCategory(dimension);
                if (category != null) {
                    AttributeGroupDTO attributeGroup = new AttributeGroupDTO();
                    attributeGroup.setId(category.getId());
                    attributeGroup.setName(category.getLabel());
                    list.add(attributeGroup);
                }
            }
            // sort the groups in the list by name (fallback on id)
            Collections.sort(list, new Comparator<AttributeGroupDTO>() {

                @Override
                public int compare(AttributeGroupDTO g1, AttributeGroupDTO g2) {
                    int result = g1.getName().compareToIgnoreCase(g2.getName());
                    if (result != 0) {
                        return result;
                    } else {
                        return ((Integer) g1.getId()).compareTo(g2.getId());
                    }
                }
            });
            callback.onSuccess(new AttributeGroupResult(list));
        }

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }
    });
}
Also used : AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) Dimension(org.activityinfo.shared.report.model.Dimension) GetAttributeGroupsDimension(org.activityinfo.shared.command.GetAttributeGroupsDimension) Comparator(java.util.Comparator) PivotSites(org.activityinfo.shared.command.PivotSites) AttributeGroupResult(org.activityinfo.shared.command.result.AttributeGroupResult) Bucket(org.activityinfo.shared.command.result.Bucket) ArrayList(java.util.ArrayList) List(java.util.List) EntityCategory(org.activityinfo.shared.report.content.EntityCategory)

Aggregations

AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)16 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)9 IndicatorDTO (org.activityinfo.shared.dto.IndicatorDTO)7 AttributeDTO (org.activityinfo.shared.dto.AttributeDTO)6 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)5 ModelData (com.extjs.gxt.ui.client.data.ModelData)3 GetSchema (org.activityinfo.shared.command.GetSchema)3 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 GetAttributeGroupsDimension (org.activityinfo.shared.command.GetAttributeGroupsDimension)2 AttributeGroupResult (org.activityinfo.shared.command.result.AttributeGroupResult)2 CreateResult (org.activityinfo.shared.command.result.CreateResult)2 AdminLevelDTO (org.activityinfo.shared.dto.AdminLevelDTO)2 FieldBinding (com.extjs.gxt.ui.client.binding.FieldBinding)1 TreeGridDragSource (com.extjs.gxt.ui.client.dnd.TreeGridDragSource)1 TreeGridDropTarget (com.extjs.gxt.ui.client.dnd.TreeGridDropTarget)1 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)1 DNDEvent (com.extjs.gxt.ui.client.event.DNDEvent)1 DNDListener (com.extjs.gxt.ui.client.event.DNDListener)1