Search in sources :

Example 1 with LocationTypeDTO

use of org.activityinfo.legacy.shared.model.LocationTypeDTO in project activityinfo by bedatadriven.

the class LocationTypeProxy method load.

@Override
public void load(DataReader<ListLoadResult<LocationTypeEntry>> reader, Object loadConfig, AsyncCallback<ListLoadResult<LocationTypeEntry>> callback) {
    dispatcher.execute(new GetSchema()).then(new Function<SchemaDTO, ListLoadResult<LocationTypeEntry>>() {

        @Override
        public ListLoadResult<LocationTypeEntry> apply(SchemaDTO schema) {
            // Build a dictionary of databases that have been shared with the user
            Map<Integer, String> databaseNames = new HashMap<>();
            for (UserDatabaseDTO db : schema.getDatabases()) {
                databaseNames.put(db.getId(), db.getName());
            }
            List<LocationTypeEntry> list = new ArrayList<>();
            for (LocationTypeDTO locationType : schema.getCountryById(countryId).getLocationTypes()) {
                if (!locationType.isDeleted()) {
                    if (locationType.getDatabaseId() == null) {
                        list.add(new LocationTypeEntry(locationType));
                    } else {
                        list.add(new LocationTypeEntry(locationType, databaseNames.get(locationType.getDatabaseId())));
                    }
                }
            }
            Collections.sort(list);
            return new BaseListLoadResult<>(list);
        }
    }).then(callback);
}
Also used : UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) LocationTypeDTO(org.activityinfo.legacy.shared.model.LocationTypeDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) Function(com.google.common.base.Function) GetSchema(org.activityinfo.legacy.shared.command.GetSchema)

Example 2 with LocationTypeDTO

use of org.activityinfo.legacy.shared.model.LocationTypeDTO in project activityinfo by bedatadriven.

the class ActivityPolicy method applyProperties.

private void applyProperties(Activity activity, PropertyMap changes) {
    if (changes.containsKey(NAME_PROPERTY)) {
        String name = truncate(changes.get(NAME_PROPERTY));
        activity.setName(name);
        String json = JsonHelper.readJson(activity);
        updateFormClass(activity, name, json);
    }
    if (changes.containsKey(LOCATION_TYPE_ID_PROPERTY)) {
        LocationType location = em.find(LocationType.class, changes.get(LOCATION_TYPE_ID_PROPERTY));
        if (location != null) {
            activity.setLocationType(location);
        }
    }
    if (changes.containsKey(FOLDER_ID_PROPERTY)) {
        updateFolder(activity, changes);
    }
    if (changes.containsKey(CATEGORY_PROPERTY)) {
        updateCategory(activity, changes);
    }
    if (changes.containsKey(LOCATION_TYPE)) {
        LocationTypeDTO newLocationType = changes.get(LOCATION_TYPE);
        activity.setLocationType(em.getReference(LocationType.class, newLocationType.getId()));
    }
    if (changes.containsKey("mapIcon")) {
        activity.setMapIcon(changes.get("mapIcon"));
    }
    if (changes.containsKey(REPORTING_FREQUENCY_PROPERTY)) {
        activity.setReportingFrequency(changes.get(REPORTING_FREQUENCY_PROPERTY));
    }
    if (changes.containsKey(PUBLISHED_PROPERTY)) {
        activity.setPublished(changes.get(PUBLISHED_PROPERTY));
    }
    if (changes.containsKey(CLASSIC_VIEW_PROPERTY)) {
        activity.setClassicView(changes.get(CLASSIC_VIEW_PROPERTY));
    }
    if (changes.containsKey(SORT_ORDER_PROPERTY)) {
        activity.setSortOrder(changes.get(SORT_ORDER_PROPERTY));
    }
    activity.getDatabase().setLastSchemaUpdate(new Date());
}
Also used : LocationTypeDTO(org.activityinfo.legacy.shared.model.LocationTypeDTO) Date(java.util.Date)

Aggregations

LocationTypeDTO (org.activityinfo.legacy.shared.model.LocationTypeDTO)2 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)1 Function (com.google.common.base.Function)1 Date (java.util.Date)1 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)1 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)1 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)1