Search in sources :

Example 16 with SchemaHolder

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

the class JarGeneratorController method generateJar.

@RequestMapping(value = "/jar", method = RequestMethod.GET)
public void generateJar(HttpServletResponse response) throws IOException, NotFoundException, CannotCompileException {
    response.setContentType(APPLICATION_JAVA_ARCHIVE);
    response.setCharacterEncoding(UTF_8);
    response.setHeader("Content-Disposition", format("attachment; filename=%s.jar", encode("mds-entities", UTF_8)));
    OutputStream output = response.getOutputStream();
    SchemaHolder schemaHolder = entityService.getSchema();
    File jar = jarGeneratorService.generate(schemaHolder);
    try (FileInputStream input = new FileInputStream(jar)) {
        IOUtils.copy(input, output);
    }
}
Also used : OutputStream(java.io.OutputStream) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) File(java.io.File) FileInputStream(java.io.FileInputStream) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with SchemaHolder

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

the class MdsBundleIT method verifyUniqueConstraint.

private void verifyUniqueConstraint() throws Exception {
    Object instance = service.getClassType().newInstance();
    PropertyUtils.setProperty(instance, "someString", "uniqueVal");
    service.create(instance);
    Object dupeInstance = service.getClassType().newInstance();
    PropertyUtils.setProperty(dupeInstance, "someString", "uniqueVal");
    // this should violate the unique constraint
    boolean caught = false;
    try {
        service.create(dupeInstance);
    } catch (RuntimeException e) {
        caught = true;
    }
    assertTrue("Unique constraint had no effect!", caught);
    // verify constraint removal
    Long entityId = entityService.getEntityByClassName(FOO_CLASS).getId();
    Long fieldId = getFieldIdByName(entityService.getFields(entityId), "someString");
    DraftData draft = DraftBuilder.forFieldEdit(fieldId, "basic.unique", false);
    entityService.saveDraftEntityChanges(entityId, draft);
    entityService.commitChanges(entityId);
    SchemaHolder schemaHolder = entityService.getSchema();
    generator.regenerateMdsDataBundle(schemaHolder, true);
    service = (MotechDataService) ServiceRetriever.getService(bundleContext, ClassName.getInterfaceName(FOO_CLASS), true);
    // should succeed now, no exception is enough for us at this point
    dupeInstance = service.getClassType().newInstance();
    PropertyUtils.setProperty(dupeInstance, "someString", "uniqueVal");
    service.create(dupeInstance);
}
Also used : DraftData(org.motechproject.mds.dto.DraftData) SchemaHolder(org.motechproject.mds.dto.SchemaHolder)

Example 18 with SchemaHolder

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

the class MdsBundleIT method testEntitiesBundleInstallsProperly.

private void testEntitiesBundleInstallsProperly(boolean withCache) throws Exception {
    final String serviceName = ClassName.getInterfaceName(FOO_CLASS);
    // Some additional preparation needed for second run without l2 cache
    if (!withCache) {
        clearEntities();
        SchemaHolder schemaHolder = entityService.getSchema();
        generator.regenerateMdsDataBundle(schemaHolder);
    }
    prepareTestEntities();
    Bundle entitiesBundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, MDS_ENTITIES_SYMBOLIC_NAME);
    assertNotNull(entitiesBundle);
    service = (MotechDataService) ServiceRetriever.getService(bundleContext, serviceName, true);
    Class<?> objectClass = entitiesBundle.loadClass(FOO_CLASS);
    getLogger().info("Loaded class: " + objectClass.getName());
    clearInstances();
    verifyMetadataRetrieval();
    verifyInstanceCreatingAndRetrieving(objectClass);
    verifyInstanceCreatingOrUpdating(objectClass);
    // regular lookups
    verifyLookups(false);
    // using the lookup service
    verifyLookups(true);
    verifyComboboxValueUpdate();
    verifyInstanceUpdating();
    verifyCustomQuery();
    verifyCsvImport();
    verifyCsvImportIsOneTransaction();
    verifyColumnNameChange();
    verifyComboboxDataMigration();
    verifyInstanceDeleting();
    verifyRestDocumentation();
    verifyUniqueConstraint();
    service.deleteAll();
}
Also used : Bundle(org.osgi.framework.Bundle) SchemaHolder(org.motechproject.mds.dto.SchemaHolder)

Example 19 with SchemaHolder

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

the class JarGeneratorServiceContextIT method testGenerate.

@Test
public void testGenerate() throws Exception {
    SchemaHolder schemaHolder = entityService.getSchema();
    File file = generator.generate(schemaHolder);
    try (FileInputStream stream = new FileInputStream(file);
        JarInputStream input = new JarInputStream(stream)) {
        assertManifest(input);
        assertJarEntries(input);
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 20 with SchemaHolder

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

the class JarGeneratorServiceContextIT method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    MotechClassPool.clearEnhancedData();
    EntityDto entitySAMPLE = new EntityDto(null, SAMPLE);
    entitySAMPLE.setRecordHistory(true);
    EntityDto entityEXAMPLE = new EntityDto(null, EXAMPLE);
    entityEXAMPLE.setRecordHistory(true);
    EntityDto entityFOO = new EntityDto(null, FOO);
    entityFOO.setRecordHistory(true);
    // Entity without history
    EntityDto entityBAR = new EntityDto(null, BAR);
    entityBAR.setRecordHistory(false);
    entityService.createEntity(entitySAMPLE);
    entityService.createEntity(entityEXAMPLE);
    entityService.createEntity(entityFOO);
    entityService.createEntity(entityBAR);
    bundleHeaders = new BundleHeaders(bundleContext);
    Path path = Paths.get(monitor.bundleLocation());
    Files.deleteIfExists(path);
    setProperty(monitor, "bundleStarted", true);
    setProperty(monitor, "bundleInstalled", true);
    setProperty(monitor, "contextInitialized", true);
    SchemaHolder schemaHolder = entityService.getSchema();
    constructor.constructEntities(schemaHolder);
}
Also used : Path(java.nio.file.Path) EntityDto(org.motechproject.mds.dto.EntityDto) BundleHeaders(org.motechproject.osgi.web.util.BundleHeaders) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) Before(org.junit.Before)

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