Search in sources :

Example 1 with ComponentDefinition

use of org.jaffa.presentation.portlet.component.ComponentDefinition in project jaffa-framework by jaffa-projects.

the class DefaultValueEditorComponent method obtainComponents.

/**
 * Create a List of Lists, each List representing a component definition, having a corresponding default value file.
 * Each List will contain the String values for: ComponentName, ComponentClass, ComponentType and DefaultValueFile.
 */
protected void obtainComponents() {
    if (m_components == null) {
        List components = new ArrayList();
        Map componentPool = Loader.getComponentPool();
        if (componentPool != null) {
            // Create a List for each ComponentDefinition
            for (Iterator i = (new TreeSet(componentPool.keySet())).iterator(); i.hasNext(); ) {
                String componentName = (String) i.next();
                ComponentDefinition cd = (ComponentDefinition) componentPool.get(componentName);
                try {
                    URL url = MaintComponent2.determineDefaultValuesUrl(Class.forName(cd.getComponentClass()));
                    if (url != null) {
                        List component = new ArrayList();
                        component.add(componentName);
                        component.add(cd.getComponentClass());
                        component.add(cd.getComponentType());
                        component.add(url.toExternalForm());
                        components.add(component);
                    } else {
                        if (log.isDebugEnabled())
                            log.debug("No default value file found for component: " + componentName);
                    }
                } catch (ClassNotFoundException e) {
                    log.warn("Class Not Found", e);
                }
            }
        }
        m_components = (List[]) components.toArray(new List[0]);
    }
}
Also used : URL(java.net.URL) ComponentDefinition(org.jaffa.presentation.portlet.component.ComponentDefinition)

Example 2 with ComponentDefinition

use of org.jaffa.presentation.portlet.component.ComponentDefinition in project jaffa-framework by jaffa-projects.

the class ComponentManagerTest method testGetRepositoryByName.

/**
 * Tests the ability of this IManager to retrieve a repository when given its String name
 */
@Test
public void testGetRepositoryByName() throws Exception {
    // A componentDefinition must be registered first
    Component component = new Component();
    String name = "q1";
    component.setId(name);
    ComponentDefinition definition = new ComponentDefinition(component);
    ContextKey key = new ContextKey(name, "components.xml", "DEF", "0-PLATFORM");
    manager.registerComponentDefinition(key, definition);
    String repo = "ComponentDefinition";
    assertEquals(repo, manager.getRepositoryByName(repo).getName());
}
Also used : ContextKey(org.jaffa.loader.ContextKey) Component(org.jaffa.presentation.portlet.component.componentdomain.Component) ComponentDefinition(org.jaffa.presentation.portlet.component.ComponentDefinition) Test(org.junit.Test)

Example 3 with ComponentDefinition

use of org.jaffa.presentation.portlet.component.ComponentDefinition in project jaffa-framework by jaffa-projects.

the class ComponentResourceLoaderTest method testXmlLoad.

/**
 * Test loading the XML config via the ComponentManager.
 * (Assumes a certain components file with particular values in
 * jaffa-framework/jaffa-core/target/test-classes/META-INF/components.xml)
 */
@Test
public void testXmlLoad() {
    ComponentManager componentManager = xmlLoaderConfig.getBean(ComponentManager.class);
    assertNull(componentManager.getComponentDefinition(null));
    assertNull(componentManager.getComponentDefinition(""));
    IRepository<ComponentDefinition> repository = componentManager.getComponentRepository();
    List<ComponentDefinition> values = repository.getAllValues();
    assertEquals(4, values.size());
    Set<ContextKey> keys = repository.getAllKeys();
    String rolesEditorKey = "Jaffa.Admin.RolesEditor";
    ContextKey rolesEditorContextKey = new ContextKey(rolesEditorKey, "different-file.xml", "NULL", "100-Highest");
    assertTrue(keys.contains(rolesEditorContextKey));
    String testFunctionViewerKey = "Jaffa.UnitTest.TestFunctionViewer";
    ContextKey testFunctionViewerContextKey = new ContextKey(testFunctionViewerKey, "different-file.xml", "NULL", "100-Highest");
    assertTrue(keys.contains(testFunctionViewerContextKey));
    ComponentDefinition reComponentDefinition = componentManager.getComponentDefinition(rolesEditorKey);
    String reType = reComponentDefinition.getComponentType();
    assertEquals("Custom", reType);
    String[] optionals = reComponentDefinition.getOptionalFunctions();
    assertEquals(0, optionals.length);
    assertNull(reComponentDefinition.getParameters());
}
Also used : ContextKey(org.jaffa.loader.ContextKey) ComponentDefinition(org.jaffa.presentation.portlet.component.ComponentDefinition) Test(org.junit.Test)

Example 4 with ComponentDefinition

use of org.jaffa.presentation.portlet.component.ComponentDefinition in project jaffa-framework by jaffa-projects.

the class SavedQuery method getCriteriaClass.

private static String getCriteriaClass(String componentRef) {
    ComponentDefinition component = Loader.getComponentPool().get(componentRef);
    List<Object> params = component.getParameters();
    for (final Object param : params) {
        if (param != null && param instanceof ObjectTypeParam) {
            if (((ObjectTypeParam) param).getClassName() != null) {
                String name = ((ObjectTypeParam) param).getName();
                String type = ((ObjectTypeParam) param).getClassName();
                if (name.equals("criteria"))
                    return type;
            }
        }
    }
    return null;
}
Also used : ComponentDefinition(org.jaffa.presentation.portlet.component.ComponentDefinition)

Example 5 with ComponentDefinition

use of org.jaffa.presentation.portlet.component.ComponentDefinition in project jaffa-framework by jaffa-projects.

the class SavedQuery method getSavedQueries.

/**
 * Return all saved queries in a JSON string
 */
public static String getSavedQueries(String componentRef, String contextRef) throws FrameworkException {
    UOW uow = null;
    try {
        StringBuffer json = new StringBuffer();
        uow = new UOW();
        SavedQuery savedQuery = null;
        Criteria criteria = new Criteria();
        criteria.setTable(SavedQueryMeta.getName());
        String userId = (String) ContextManagerFactory.instance().getProperty(PROPERTY_USER_ID);
        criteria.addCriteria(SavedQueryMeta.USER_ID, userId);
        criteria.addOrderBy(SavedQueryMeta.QUERY_NAME, Criteria.ORDER_BY_ASC);
        if (componentRef != null)
            criteria.addCriteria(SavedQueryMeta.COMPONENT_REF, componentRef);
        if (contextRef != null && !contextRef.equals(""))
            criteria.addCriteria(SavedQueryMeta.CONTEXT_REF, contextRef);
        Iterator it = uow.query(criteria).iterator();
        json.append("[");
        boolean isFirst = true;
        while (it.hasNext()) {
            String jsonCriteria;
            savedQuery = (SavedQuery) it.next();
            if (isFirst) {
                isFirst = false;
            } else {
                json.append(",");
            }
            // get criteria here and deserialize it!
            ComponentDefinition component = Loader.getComponentPool().get(componentRef);
            List<Object> params = component.getParameters();
            String criteriaClass = "";
            if (params != null) {
                for (final Object param : params) {
                    if (param != null && param instanceof ObjectTypeParam) {
                        if (((ObjectTypeParam) param).getClassName() != null) {
                            String name = ((ObjectTypeParam) param).getName();
                            String type = ((ObjectTypeParam) param).getClassName();
                            if (name.equals("criteria"))
                                criteriaClass = type;
                        }
                    }
                }
            }
            if (criteriaClass != null && !criteriaClass.equals("")) {
                // final Class<?> clazz = Class.forName(criteriaClass);
                Object payload = null;
                if (savedQuery.getCriteria() != null) {
                    try {
                        payload = JAXBHelper.unmarshalPayload(savedQuery.getCriteria(), criteriaClass);
                    } catch (Exception e) {
                        String s = "Error in unmarshalling criteria to a " + criteriaClass + " object via JAXB";
                        log.error(s, e);
                        throw new RuntimeException(s, e);
                    }
                }
                final JSONObject jsonObject = JSONObject.fromObject(payload);
                jsonCriteria = jsonObject.toString();
            } else {
                jsonCriteria = savedQuery.getCriteria();
            }
            // should build string like - ['queryName',{'criteria':{field1:value1,isDefault:true}]
            json.append("['").append(savedQuery.getQueryName()).append("', {'criteria':").append(jsonCriteria).append(", 'isDefault':").append(savedQuery.getIsDefault() ? "true" : "false").append("}]");
        }
        json.append("]");
        return json.toString();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (uow != null)
            uow.rollback();
    }
    return null;
}
Also used : FrameworkException(org.jaffa.exceptions.FrameworkException) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException) DuplicateKeyException(org.jaffa.exceptions.DuplicateKeyException) RelatedDomainObjectFoundException(org.jaffa.exceptions.RelatedDomainObjectFoundException) JAXBException(javax.xml.bind.JAXBException) ComponentDefinition(org.jaffa.presentation.portlet.component.ComponentDefinition)

Aggregations

ComponentDefinition (org.jaffa.presentation.portlet.component.ComponentDefinition)10 ContextKey (org.jaffa.loader.ContextKey)6 Component (org.jaffa.presentation.portlet.component.componentdomain.Component)5 Test (org.junit.Test)4 Components (org.jaffa.presentation.portlet.component.componentdomain.Components)2 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JAXBException (javax.xml.bind.JAXBException)1 InvalidForeignKeyException (org.jaffa.datatypes.exceptions.InvalidForeignKeyException)1 DuplicateKeyException (org.jaffa.exceptions.DuplicateKeyException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 RelatedDomainObjectFoundException (org.jaffa.exceptions.RelatedDomainObjectFoundException)1