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);
}
}
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);
}
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();
}
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);
}
}
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);
}
Aggregations