Search in sources :

Example 6 with SchemaHolder

use of org.motechproject.mds.dto.SchemaHolder in project motech by motech.

the class MdsBundleRegenerationServiceImpl method regenerateMdsDataBundle.

@Override
public void regenerateMdsDataBundle() {
    broadcast(REGENERATE_MDS_DATA_BUNDLE);
    SchemaHolder schemaHolder = entityService.getSchema();
    jarGeneratorService.regenerateMdsDataBundle(schemaHolder);
}
Also used : SchemaHolder(org.motechproject.mds.dto.SchemaHolder)

Example 7 with SchemaHolder

use of org.motechproject.mds.dto.SchemaHolder in project motech by motech.

the class MdsBundleRegenerationServiceImpl method handleMdsDataBundleRegeneration.

private void handleMdsDataBundleRegeneration(Event event) {
    if (!isBroadcastFromThisInstance(event)) {
        SchemaHolder schemaHolder = entityService.getSchema();
        jarGeneratorService.regenerateMdsDataBundle(schemaHolder);
    }
}
Also used : SchemaHolder(org.motechproject.mds.dto.SchemaHolder)

Example 8 with SchemaHolder

use of org.motechproject.mds.dto.SchemaHolder in project motech by motech.

the class MdsBundleIT method createEntityForPreferencesTest.

private EntityDto createEntityForPreferencesTest() {
    EntityDto entityDto = new EntityDto(null, FOO);
    entityDto = entityService.createEntity(entityDto);
    SchemaHolder schemaHolder = entityService.getSchema();
    generator.regenerateMdsDataBundle(schemaHolder);
    List<FieldDto> fields = new ArrayList<>();
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.BOOLEAN, new FieldBasicDto("Some Boolean", "someBoolean"), false, false, false, false, false, null, null, null, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.STRING, new FieldBasicDto("Some String", "someString"), false, false, false, false, false, null, null, asList(new SettingDto("mds.form.label.textarea", false, BOOLEAN)), null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.INTEGER, new FieldBasicDto("Some Integer", "someInteger"), false, false, false, false, false, null, null, null, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.INTEGER, new FieldBasicDto("Other Integer", "otherInteger"), false, false, false, false, false, null, null, null, null));
    entityService.addFields(entityDto, fields);
    Map<String, Long> displayedFields = new HashMap<>();
    displayedFields.put("someInteger", 1L);
    displayedFields.put("someBoolean", 2L);
    displayedFields.put("someString", 3L);
    entityService.addDisplayedFields(entityDto, displayedFields);
    schemaHolder = entityService.getSchema();
    generator.regenerateMdsDataBundle(schemaHolder);
    return entityDto;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) SettingDto(org.motechproject.mds.dto.SettingDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 9 with SchemaHolder

use of org.motechproject.mds.dto.SchemaHolder in project motech by motech.

the class MdsBundleIT method prepareTestEntities.

private void prepareTestEntities() throws IOException {
    getLogger().info("Preparing entities for testing");
    EntityDto entityDto = new EntityDto(9999L, FOO);
    entityDto = entityService.createEntity(entityDto);
    SchemaHolder schemaHolder = entityService.getSchema();
    generator.regenerateMdsDataBundle(schemaHolder);
    List<FieldDto> fields = new ArrayList<>();
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.BOOLEAN, new FieldBasicDto("Some Boolean", "someBoolean"), false, null));
    // this field is unique
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.STRING, new FieldBasicDto("Some String", "someString", false, true), false, null, null, asList(new SettingDto("mds.form.label.textarea", false, BOOLEAN)), null));
    // test with capitalized name
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.STRING, new FieldBasicDto("Capital Name", "CapitalName"), false, null, null, asList(new SettingDto("mds.form.label.textarea", false, BOOLEAN)), null));
    fields.add(new FieldDto(null, entityDto.getId(), COLLECTION, new FieldBasicDto("Some List", "someList"), false, null, null, asList(new SettingDto(Constants.Settings.COMBOBOX_VALUES, new LinkedList<>(), COLLECTION, REQUIRE), new SettingDto(Constants.Settings.ALLOW_USER_SUPPLIED, true, BOOLEAN), new SettingDto(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS, true, BOOLEAN)), null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.DATETIME, new FieldBasicDto("dateTime", "someDateTime"), false, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.DATETIME8, new FieldBasicDto("someJavaDateTime", "someJavaDateTime"), false, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.MAP, new FieldBasicDto("someMap", "someMap"), false, Arrays.asList(new MetadataDto(MAP_KEY_TYPE, String.class.getName()), new MetadataDto(MAP_VALUE_TYPE, TestClass.class.getName())), null, null, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.PERIOD, new FieldBasicDto("somePeriod", "somePeriod"), false, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.BLOB, new FieldBasicDto("someBlob", "someBlob"), false, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.LOCAL_DATE, new FieldBasicDto("someLocalDate", "someLocalDate"), false, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.LOCAL_DATE8, new FieldBasicDto("someJavaDate", "someJavaDate"), false, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.DATE, new FieldBasicDto("someDate", "someDate"), false, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.TIME, new FieldBasicDto("someTime", "someTime"), false, null));
    List<SettingDto> decimalSettings = asList(new SettingDto("mds.form.label.precision", 10), new SettingDto("mds.form.label.scale", 5));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.DOUBLE, new FieldBasicDto("Some Decimal", "someDecimal"), false, null, null, decimalSettings, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.INTEGER, new FieldBasicDto("someInteger", "someInt"), false, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.COLLECTION, new FieldBasicDto("Some Enum", "someEnum"), false, null, null, asList(new SettingDto(Constants.Settings.COMBOBOX_VALUES, asList("one", "two", "three"), COLLECTION, REQUIRE), new SettingDto(Constants.Settings.ALLOW_USER_SUPPLIED, false, BOOLEAN), new SettingDto(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS, false, BOOLEAN)), null));
    entityService.addFields(entityDto, fields);
    List<LookupDto> lookups = new ArrayList<>();
    List<LookupFieldDto> lookupFields = new ArrayList<>();
    lookupFields.add(new LookupFieldDto(null, "someBoolean", LookupFieldType.VALUE));
    lookups.add(new LookupDto("By boolean", false, false, lookupFields, true, "byBool", asList("someBoolean")));
    lookupFields = new ArrayList<>();
    lookupFields.add(new LookupFieldDto(null, "someString", LookupFieldType.VALUE));
    lookups.add(new LookupDto("By unique String", true, false, lookupFields, true, "byUniqueString", asList("someString")));
    lookupFields = new ArrayList<>();
    lookupFields.add(new LookupFieldDto(null, "someBoolean", LookupFieldType.VALUE));
    lookupFields.add(new LookupFieldDto(null, "someDateTime", LookupFieldType.RANGE));
    lookupFields.add(new LookupFieldDto(null, "someString", LookupFieldType.SET));
    lookupFields.add(new LookupFieldDto(null, "someList", LookupFieldType.VALUE));
    lookups.add(new LookupDto("Combined", false, false, lookupFields, true));
    lookupFields = new ArrayList<>();
    lookupFields.add(new LookupFieldDto(null, "someInt", LookupFieldType.VALUE, "<="));
    lookups.add(new LookupDto("With custom operator", false, false, lookupFields, true, "customOperator", asList("someInt")));
    lookupFields = new ArrayList<>();
    lookupFields.add(new LookupFieldDto(null, "someString", LookupFieldType.VALUE, "matches()"));
    lookups.add(new LookupDto("With matches", false, false, lookupFields, true, "matchesOperator", asList("someString")));
    lookupFields = new ArrayList<>();
    lookupFields.add(new LookupFieldDto(null, "someString", LookupFieldType.VALUE, Constants.Operators.MATCHES_CASE_INSENSITIVE));
    lookups.add(new LookupDto("With matches case insensitive", false, false, lookupFields, true, "matchesOperatorCI", singletonList("someString")));
    entityService.addLookups(entityDto.getId(), lookups);
    schemaHolder = entityService.getSchema();
    generator.regenerateMdsDataBundle(schemaHolder);
    getLogger().info("Entities ready for testing");
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) MetadataDto(org.motechproject.mds.dto.MetadataDto) LinkedList(java.util.LinkedList) EntityDto(org.motechproject.mds.dto.EntityDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) SettingDto(org.motechproject.mds.dto.SettingDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 10 with SchemaHolder

use of org.motechproject.mds.dto.SchemaHolder in project motech by motech.

the class MdsBundleIT method verifyColumnNameChange.

private void verifyColumnNameChange() throws ClassNotFoundException, InterruptedException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    getLogger().info("Verifying column name change");
    Long entityId = entityService.getEntityByClassName(FOO_CLASS).getId();
    List<Field> fields = entityService.getEntityDraft(entityId).getFields();
    Field fieldToUpdate = findFieldByName(fields, "someString");
    entityService.saveDraftEntityChanges(entityId, DraftBuilder.forFieldEdit(fieldToUpdate.getId(), "basic.name", "newFieldName"));
    entityService.commitChanges(entityId);
    SchemaHolder schemaHolder = entityService.getSchema();
    generator.regenerateMdsDataBundle(schemaHolder);
    FieldDto fieldToUpdateDto = DtoHelper.findByName(entityService.getEntityFields(entityId), "newFieldName");
    assertNotNull("Unable to find field named 'newFieldName'", fieldToUpdate);
    assertEquals(String.class.getName(), fieldToUpdateDto.getType().getTypeClass());
    service = (MotechDataService) ServiceRetriever.getService(bundleContext, ClassName.getInterfaceName(FOO_CLASS), true);
    Object retrieved = service.retrieveAll(QueryParams.ascOrder("someDateTime")).get(0);
    Object fieldValue = MethodUtils.invokeMethod(retrieved, "getNewFieldName", null);
    assertNotNull(fieldValue);
    entityId = entityService.getEntityByClassName(FOO_CLASS).getId();
    fields = entityService.getEntityDraft(entityId).getFields();
    fieldToUpdate = findFieldByName(fields, "newFieldName");
    entityService.saveDraftEntityChanges(entityId, DraftBuilder.forFieldEdit(fieldToUpdate.getId(), "basic.name", "someString"));
    entityService.commitChanges(entityId);
    schemaHolder = entityService.getSchema();
    generator.regenerateMdsDataBundle(schemaHolder);
    service = (MotechDataService) ServiceRetriever.getService(bundleContext, ClassName.getInterfaceName(FOO_CLASS), true);
}
Also used : Field(org.motechproject.mds.domain.Field) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Aggregations

SchemaHolder (org.motechproject.mds.dto.SchemaHolder)24 EntityDto (org.motechproject.mds.dto.EntityDto)7 FieldDto (org.motechproject.mds.dto.FieldDto)5 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)5 Test (org.junit.Test)4 StopWatch (org.apache.commons.lang.time.StopWatch)3 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Before (org.junit.Before)2 MDSProcessorOutput (org.motechproject.mds.annotations.internal.MDSProcessorOutput)2 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)2 DraftData (org.motechproject.mds.dto.DraftData)2 LookupDto (org.motechproject.mds.dto.LookupDto)2 SettingDto (org.motechproject.mds.dto.SettingDto)2