Search in sources :

Example 1 with BundleHeaders

use of org.motechproject.osgi.web.util.BundleHeaders in project motech by motech.

the class EntityProcessor method process.

@Override
protected void process(AnnotatedElement element) {
    BundleHeaders bundleHeaders = new BundleHeaders(getBundle());
    EntityProcessorOutput entityProcessorOutput = new EntityProcessorOutput();
    Class clazz = (Class) element;
    Class<Entity> ann = ReflectionsUtil.getAnnotationClass(clazz, Entity.class);
    Annotation annotation = AnnotationUtils.findAnnotation(clazz, ann);
    if (null != annotation) {
        String className = clazz.getName();
        String name = ReflectionsUtil.getAnnotationValue(annotation, NAME, ClassName.getSimpleName(className));
        String module = ReflectionsUtil.getAnnotationValue(annotation, MODULE, bundleHeaders.getName(), bundleHeaders.getSymbolicName());
        String bundleSymbolicName = getBundle().getSymbolicName();
        String namespace = ReflectionsUtil.getAnnotationValue(annotation, NAMESPACE);
        String tableName = ReflectionsUtil.getAnnotationValue(annotation, TABLE_NAME);
        boolean recordHistory = Boolean.parseBoolean(ReflectionsUtil.getAnnotationValue(annotation, HISTORY));
        boolean nonEditable = Boolean.parseBoolean(ReflectionsUtil.getAnnotationValue(annotation, NON_EDITABLE));
        EntityDto entity = getSchemaHolder().getEntityByClassName(className);
        RestOptionsDto restOptions = new RestOptionsDto();
        TrackingDto tracking = new TrackingDto();
        Collection<FieldDto> fields;
        if (entity == null) {
            LOGGER.debug("Creating DDE for {}", className);
            entity = new EntityDto(null, className, name, module, namespace, tableName, recordHistory, SecurityMode.EVERYONE, null, null, null, clazz.getSuperclass().getName(), Modifier.isAbstract(clazz.getModifiers()), false, bundleSymbolicName);
        } else {
            LOGGER.debug("DDE for {} already exists, updating if necessary", className);
            AdvancedSettingsDto advancedSettings = getSchemaHolder().getAdvancedSettings(className);
            restOptions = advancedSettings.getRestOptions();
            tracking = advancedSettings.getTracking();
            entity.setBundleSymbolicName(bundleSymbolicName);
            entity.setModule(module);
        }
        if (!tracking.isModifiedByUser()) {
            tracking.setRecordHistory(recordHistory);
            tracking.setNonEditable(nonEditable);
        }
        setSecurityOptions(element, entity);
        // per entity maxFetchDepth that will be passed to the Persistence Manager
        setMaxFetchDepth(entity, annotation);
        entityProcessorOutput.setEntityProcessingResult(entity);
        fields = findFields(clazz, entity);
        String versionField = getVersionFieldName(clazz);
        addVersionMetadata(fields, versionField);
        addDefaultFields(entity, fields);
        restOptions = processRestOperations(clazz, restOptions);
        restOptions = findRestFields(clazz, restOptions, fields);
        updateUiChangedFields(fields, className);
        updateResults(entityProcessorOutput, clazz, fields, restOptions, tracking, versionField);
        add(entity);
        processingResult.add(entityProcessorOutput);
        MotechClassPool.registerDDE(entity.getClassName());
    } else {
        LOGGER.debug("Did not find Entity annotation in class: {}", clazz.getName());
    }
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Entity(org.motechproject.mds.annotations.Entity) BundleHeaders(org.motechproject.osgi.web.util.BundleHeaders) Annotation(java.lang.annotation.Annotation) TrackingDto(org.motechproject.mds.dto.TrackingDto) EntityDto(org.motechproject.mds.dto.EntityDto) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) RestOptionsDto(org.motechproject.mds.dto.RestOptionsDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 2 with BundleHeaders

use of org.motechproject.osgi.web.util.BundleHeaders in project motech by motech.

the class MdsBundleHelper method isBundleMdsDependent.

public static boolean isBundleMdsDependent(Bundle bundle) {
    if (bundle == null) {
        return false;
    } else {
        BundleHeaders headers = new BundleHeaders(bundle);
        // check for Mds imports
        String imports = headers.getStringValue(org.osgi.framework.Constants.IMPORT_PACKAGE);
        if (StringUtils.contains(imports, Constants.Packages.BASE)) {
            return true;
        }
        // finally check for dynamic imports, if someone imports dynamically everything
        // we have to assume it can use MDS
        String dynamicImport = headers.getStringValue(org.osgi.framework.Constants.DYNAMICIMPORT_PACKAGE);
        return StringUtils.contains(dynamicImport, '*') || StringUtils.contains(dynamicImport, Constants.Packages.BASE);
    }
}
Also used : BundleHeaders(org.motechproject.osgi.web.util.BundleHeaders)

Example 3 with BundleHeaders

use of org.motechproject.osgi.web.util.BundleHeaders in project motech by motech.

the class HttpServiceTrackers method addTrackerFor.

/**
 * Creates an {@link HttpServiceTracker} instance for the given bundle.
 * @param bundle the bundle for which the tracker should be created
 * @return the newly created tracker
 */
public HttpServiceTracker addTrackerFor(Bundle bundle) {
    LOGGER.debug("Adding HTTP service tracker for: {}", nullSafeSymbolicName(bundle));
    HttpServiceTracker httpServiceTracker = new HttpServiceTracker(bundle.getBundleContext(), getResourceMapping(new BundleHeaders(bundle)));
    trackers.put(nullSafeSymbolicName(bundle), httpServiceTracker);
    httpServiceTracker.start();
    LOGGER.debug("Registered HTTP service tracker for: {}", nullSafeSymbolicName(bundle));
    return httpServiceTracker;
}
Also used : HttpServiceTracker(org.motechproject.osgi.web.tracker.internal.HttpServiceTracker) BundleHeaders(org.motechproject.osgi.web.util.BundleHeaders)

Example 4 with BundleHeaders

use of org.motechproject.osgi.web.util.BundleHeaders 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)

Example 5 with BundleHeaders

use of org.motechproject.osgi.web.util.BundleHeaders in project motech by motech.

the class JarGeneratorServiceImpl method setBundleContext.

@Autowired
public void setBundleContext(BundleContext bundleContext) {
    this.bundleContext = bundleContext;
    this.bundleHeaders = new BundleHeaders(bundleContext);
}
Also used : BundleHeaders(org.motechproject.osgi.web.util.BundleHeaders) Autowired(org.springframework.beans.factory.annotation.Autowired)

Aggregations

BundleHeaders (org.motechproject.osgi.web.util.BundleHeaders)5 EntityDto (org.motechproject.mds.dto.EntityDto)2 Annotation (java.lang.annotation.Annotation)1 Path (java.nio.file.Path)1 Before (org.junit.Before)1 Entity (org.motechproject.mds.annotations.Entity)1 MdsEntity (org.motechproject.mds.domain.MdsEntity)1 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)1 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)1 FieldDto (org.motechproject.mds.dto.FieldDto)1 RestOptionsDto (org.motechproject.mds.dto.RestOptionsDto)1 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)1 TrackingDto (org.motechproject.mds.dto.TrackingDto)1 HttpServiceTracker (org.motechproject.osgi.web.tracker.internal.HttpServiceTracker)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1