Package com.volantis.devrep.repository.impl.devices.policy

Examples of com.volantis.devrep.repository.impl.devices.policy.DefaultPolicyDescriptor


                        new JDBCDeviceRepositoryAccessor(repository, location);

                Connection conn = connection.getConnection();
                createTables(conn);

                DefaultPolicyDescriptor descriptor =
                        new DefaultPolicyDescriptor();
                descriptor.setCategory("category");
                DefaultOrderedSetPolicyType type =
                        new DefaultOrderedSetPolicyType(
                                new DefaultBooleanPolicyType());
                descriptor.setPolicyType(type);
                accessor.addPolicyDescriptor(connection, "oset", descriptor);
                accessor.removePolicyDescriptor(connection, "oset");

                // Check the database contents are empty
                checkAllEmpty(conn);
View Full Code Here


                        new JDBCDeviceRepositoryAccessor(repository, location);

                Connection conn = connection.getConnection();
                createTables(conn);

                DefaultPolicyDescriptor descriptor =
                        new DefaultPolicyDescriptor();
                descriptor.setCategory("category");
                DefaultUnorderedSetPolicyType type =
                        new DefaultUnorderedSetPolicyType(
                                new DefaultBooleanPolicyType());
                descriptor.setPolicyType(type);
                accessor.addPolicyDescriptor(connection, "uset", descriptor);

                // Check the database contents
                checkCategoryRow(conn, null, 0, "category");
                checkPolicyTypeRow(conn, null, "uset", 0, 0);
View Full Code Here

                        new JDBCDeviceRepositoryAccessor(repository, location);

                Connection conn = connection.getConnection();
                createTables(conn);

                DefaultPolicyDescriptor descriptor =
                        new DefaultPolicyDescriptor();
                descriptor.setCategory("category");
                DefaultUnorderedSetPolicyType type =
                        new DefaultUnorderedSetPolicyType(
                                new DefaultBooleanPolicyType());
                descriptor.setPolicyType(type);
                accessor.addPolicyDescriptor(connection, "uset", descriptor);
                accessor.removePolicyDescriptor(connection, "uset");

                // Check the database contents are empty
                checkAllEmpty(conn);
View Full Code Here

                        new JDBCDeviceRepositoryAccessor(repository, location);

                Connection conn = connection.getConnection();
                createTables(conn);

                DefaultPolicyDescriptor descriptor =
                        new DefaultPolicyDescriptor();

                // boolean
                descriptor.setCategory("category1");
                descriptor.setPolicyType(new DefaultBooleanPolicyType());
                accessor.addPolicyDescriptor(connection, "bool1", descriptor);
                accessor.addPolicyDescriptor(connection, "bool2", descriptor);
                policyCategoryCount+=1;
                policyTypeCount+=2;
                typesCount+=2;
                checkCounts(conn);

                // int
                descriptor.setPolicyType(new DefaultIntPolicyType());
                accessor.addPolicyDescriptor(connection, "int1", descriptor);
                accessor.addPolicyDescriptor(connection, "int2", descriptor);
                policyTypeCount+=2;
                typesCount+=2;
                checkCounts(conn);

                // range
                descriptor.setPolicyType(new DefaultRangePolicyType(6, 9));
                accessor.addPolicyDescriptor(connection, "range1", descriptor);
                accessor.addPolicyDescriptor(connection, "range2", descriptor);
                policyTypeCount+=2;
                typesCount+=2;
                typesRangeCount+=2;
                checkCounts(conn);

                // selection
                descriptor.setCategory("category2");
                DefaultSelectionPolicyType selection =
                        new DefaultSelectionPolicyType();
                selection.addKeyword("keyword1");
                selection.addKeyword("keyword2");
                selection.complete();
                descriptor.setPolicyType(selection);
                accessor.addPolicyDescriptor(connection, "selection1", descriptor);
                accessor.addPolicyDescriptor(connection, "selection2", descriptor);
                policyCategoryCount+=1;
                policyTypeCount+=2;
                typesCount+=2;
                typesSelectionCount+=4;
                checkCounts(conn);

                // text
                descriptor.setPolicyType(new DefaultTextPolicyType());
                accessor.addPolicyDescriptor(connection, "text1", descriptor);
                accessor.addPolicyDescriptor(connection, "text2", descriptor);
                policyTypeCount+=2;
                typesCount+=2;
                checkCounts(conn);

                // ordered set
                PolicyType oset = new DefaultUnorderedSetPolicyType(
                                new DefaultBooleanPolicyType());
                descriptor.setPolicyType(oset);
                accessor.addPolicyDescriptor(connection, "oset1", descriptor);
                accessor.addPolicyDescriptor(connection, "oset2", descriptor);
                policyTypeCount+=2;
                typesCount+=4;
                typesSetCount+=2;
                checkCounts(conn);

                // unordered set
                descriptor.setCategory("category3");
                PolicyType uset = new DefaultUnorderedSetPolicyType(
                                new DefaultIntPolicyType());
                descriptor.setPolicyType(uset);
                accessor.addPolicyDescriptor(connection, "uset1", descriptor);
                accessor.addPolicyDescriptor(connection, "uset2", descriptor);
                policyCategoryCount+=1;
                policyTypeCount+=2;
                typesCount+=4;
                typesSetCount+=2;
                checkCounts(conn);

                // structure
                DefaultStructurePolicyType type =
                        new DefaultStructurePolicyType();
                type.addFieldType("field1", new DefaultBooleanPolicyType());
                type.addFieldType("field2", new DefaultRangePolicyType(2, 99));
                type.complete();
                descriptor.setPolicyType(type);
                accessor.addPolicyDescriptor(connection, "structure1", descriptor);
                accessor.addPolicyDescriptor(connection, "structure2", descriptor);
                policyTypeCount+=2;
                typesCount+=6;
                typesStructureCount+=4;
View Full Code Here

     */
    public void addPolicyDescriptor(RepositoryConnection connection,
            String policyName, PolicyType type)
            throws RepositoryException {

        DefaultPolicyDescriptor descriptor = new DefaultPolicyDescriptor();
        descriptor.setPolicyType(type);
        addPolicyDescriptor(connection, policyName, descriptor);
    }
View Full Code Here

            RepositoryConnection connection,
            String policyName,
            Locale locale)
            throws RepositoryException {

        DefaultPolicyDescriptor descriptor = null;

         // Cast the repository connection to a JDBC Connection.
        JDBCRepositoryConnection jdbcConnection
                = (JDBCRepositoryConnection) connection;

        // Cast the repository connection to a JDBC Connection in
        // order to get the java.sql.Connection out.
        Connection sqlConnection = ((JDBCRepositoryConnection) connection).
                getConnection();

        PreparedStatement pstmt = null;
        ResultSet rs = null;

        // resolve field names
        String projectField = resolveFieldName(jdbcConnection, PROJECT_COLUMN_NAMES);
        String policyDescNameField = resolveFieldName(jdbcConnection, POLICY_DESC_NAMES);
        String policyHelpField = resolveFieldName(jdbcConnection, POLICY_HELP_COLUMN_NAMES);
        String policyField = resolveFieldName(jdbcConnection, POLICY_COLUMN_NAMES);
        String languageField = resolveFieldName(jdbcConnection, LANGUAGE_COLUMN_NAMES);
        String typeIDField = resolveFieldName(jdbcConnection, TYPE_ID_COLUMN_NAMES);
        String typeInstanceIDField = resolveFieldName(jdbcConnection, TYPE_INSTANCE_ID_COLUMN_NAMES);


        // resolve table names
        String vmTypesTable = resolveTableName(jdbcConnection, VMTYPES);
        String vmPolicyTypeTable = resolveTableName(jdbcConnection, VMPOLICY_TYPE);
        String vmPolicyLangTable = resolveTableName(jdbcConnection, VMPOLICY_LANG);

        try {
            String projectName = getProjectName();
            // Do a join over VMTYPES and VMPOLICY_TYPE to get the type for
            // the given policy name and project.
            String sql =
                    "select "
                    + typeIDField + " , "
                    + vmTypesTable + "." + typeInstanceIDField +
                    " from "
                    + vmTypesTable + " , "
                    + vmPolicyTypeTable +
                    " where "
                    + vmTypesTable + "." + typeInstanceIDField
                    + " = "
                    + vmPolicyTypeTable + "." + typeInstanceIDField +
                    " and "
                    + vmPolicyTypeTable + "." + projectField + " = ? " +
                    " and "
                    + vmTypesTable + "." + projectField + " = ? "
                    + " and " + vmPolicyTypeTable + "." + policyField + " = ?";

            pstmt = sqlConnection.prepareStatement(sql);
            JDBCAccessorHelper.setStringValue(pstmt, 1, projectName);
            JDBCAccessorHelper.setStringValue(pstmt, 2, projectName);
            JDBCAccessorHelper.setStringValue(pstmt, 3, policyName);

            if (logger.isDebugEnabled()) {
                logger.debug(sql);
            }

            rs = pstmt.executeQuery();

            // There should only be zero or one match.
            if (rs.next()) {

                int type = rs.getInt(1);
                int typeID = rs.getInt(2);
                // Close the result set.
                rs.close();

                PolicyType policyType = getPolicyType(
                        jdbcConnection, projectName, type, typeID);

                descriptor = new DefaultPolicyDescriptor();
                descriptor.setPolicyType(policyType);
            }
        } catch (SQLException sqle) {
            logger.error("sql-exception", sqle);
            throw new JDBCRepositoryException(sqle);
        } finally {
            close(pstmt);
        }
        if (descriptor != null) {
            Statement stmt = null;
            try {
                stmt = sqlConnection.createStatement();
                final String sql =
                    "select " + languageField + " , " + policyDescNameField + " , " +
                        policyHelpField +
                    " from " + vmPolicyLangTable +
                    " where " +
                    policyField + " = " +
                        JDBCAccessorHelper.quoteValue(policyName) +
                    " and " +
                    projectField + " = " +
                        JDBCAccessorHelper.quoteValue(getProjectName());

                if (logger.isDebugEnabled()){
                    logger.debug(sql);
                }

                rs = stmt.executeQuery(sql);
                final String[] values = getBestMatchingValues(jdbcConnection,
                    rs, new String[]{policyDescNameField, policyHelpField}, locale);
                descriptor.setPolicyDescriptiveName(values[0]);
                descriptor.setPolicyHelp(values[1]);
                descriptor.setLanguage(values[2]);
                rs.close();
            }
            catch (SQLException sqle) {
                logger.error("sql-exception", sqle);
                throw new JDBCRepositoryException(sqle);
View Full Code Here

        // fallback policy and provide some "fake" metadata to describe it.
        // Otherwise the user will get a NPE when they do this. Also, adding
        // this here (and above) means that the import process will add this
        // metadata to the JDBC repository as well.
        if (DeviceRepositoryConstants.FALLBACK_POLICY_NAME.equals(policyName)) {
            DefaultPolicyDescriptor descriptor = new DefaultPolicyDescriptor();
            descriptor.setCategory(DeviceRepositoryConstants.FALLBACK_POLICY_CATEGORY);
            // NOTE: We intentionally set the descriptive name and help to
            // default values because localising it would be a hassle.
            // This is because the properties file is currently auto-generated
            // from the Proteus version each time we make a change and we
            // can't add the full metadata to the GUI so we'd have to manually
            // re-add these property value every time. Not worth it!
            descriptor.setPolicyDescriptiveName(policyName);
            descriptor.setPolicyHelp(policyName);
            descriptor.setPolicyType(new DefaultTextPolicyType());
            descriptor.setLanguage((String) localeToLocaleFound.get(locale));
            return descriptor;
        }

        DefaultPolicyDescriptor descriptor = null;

        Policy policy = definitions.getPolicy(policyName);
        if (policy != null) {

            // Create the basic policy descriptor
            descriptor = new DefaultPolicyDescriptor();

            // Set the descriptive name
            String nameProperty =
                    DeviceRepositoryConstants.POLICY_RESOURCE_PREFIX +
                    policyName +
                    DeviceRepositoryConstants.NAME_PROPERTY_SUFFIX;
            String name = createProperties(locale).getProperty(nameProperty);
            if (name == null) {
                descriptor.setPolicyDescriptiveName(policyName);
            } else {
                descriptor.setPolicyDescriptiveName(name);
            }
            descriptor.setLanguage((String) localeToLocaleFound.get(locale));

            // Set the help
            String descriptionProperty =
                    DeviceRepositoryConstants.POLICY_RESOURCE_PREFIX +
                    policyName +
                    DeviceRepositoryConstants.DESCRIPTION_PROPERTY_SUFFIX;
            String help = createProperties(locale).getProperty(descriptionProperty);
            if (help == null) {
                descriptor.setPolicyHelp(policyName);
            } else {
                descriptor.setPolicyHelp(help);
            }

            // Set the category (short) name
            descriptor.setCategory(policy.getCategory().getName());

            // TODO: later: set the category long name/description as well so
            // that the UpdateClient merge report can access it from there
            // rather than using the old JDOM accessor code as it does now.

            // Set the the type
            // Work out the type of the policy.
            final TypeContainer typeContainer = policy.getTypeContainer();
            String typeName = typeContainer.getName();
            Type type = typeContainer.getType();
            if (typeName != null && type == null) {
                // this is a reference to a declared type.
                TypeDeclaration declaration = definitions.getType(typeName);
                if (declaration == null) {
                    throw new RepositoryException(EXCEPTION_LOCALIZER.format(
                            "repository-unable-to-find-type-information",
                            typeName));
                }
                type = declaration.getType();
            } else if (typeName == null && type != null) {
                // this is an anonymous type

            } else if (typeName == null && type == null) {
                // nothing specified, error.
                throw new RepositoryException(EXCEPTION_LOCALIZER.format(
                        "repository-unable-to-find-type-information",
                        policyName));
            } else if (typeName != null && type != null) {
                // both specified, error.
                throw new RepositoryException(EXCEPTION_LOCALIZER.format(
                        "repository-unable-to-find-type-information",
                        policyName));
            }

            // OK, we have the type, so create the descriptor for it.
            PolicyTypeCreator creator = new PolicyTypeCreator();
            PolicyType policyType = creator.calculate(type);
            descriptor.setPolicyType(policyType);
        }

        // And return the completed object
        return descriptor;
    }
View Full Code Here

                RepositoryConnection connection = createConnection();

                // ------------------------------------------------------------
                // boolean
                // ------------------------------------------------------------
                DefaultPolicyDescriptor descriptor = (DefaultPolicyDescriptor)
                        accessor.retrievePolicyDescriptor(
                                connection, "mmssupp", locale);
                // Ensure the names and help match as expected
                assertEquals("Descriptive name should match (boolean)",
                        descriptor.getPolicyDescriptiveName(),
                        "Supports MMS");
                assertEquals("Help should match (boolean)",
                        descriptor.getPolicyHelp(),
                        "Indicates whether the device supports the Multimedia" +
                        " Messaging Service (MMS)");
                assertEquals("Category should match (boolean)",
                        descriptor.getCategoryName(),
                        "system");
                // Ensure the type is of the correct type (try a cast!)
                BooleanPolicyType booleanType =
                        (BooleanPolicyType) descriptor.getPolicyType();

                // ------------------------------------------------------------
                // int
                // ------------------------------------------------------------
                descriptor = (DefaultPolicyDescriptor)
                        accessor.retrievePolicyDescriptor(
                                connection, "cpuclock", locale);
                // Ensure the names and help match as expected
                assertEquals("Descriptive name should match (int)",
                        descriptor.getPolicyDescriptiveName(),
                        "Processor clock rate");
                assertEquals("Help should match (int)",
                        descriptor.getPolicyHelp(),
                        "Processor speed in MHz. A value -1 indicates that the" +
                        " speed is unknown");
                assertEquals("Category should match (int)",
                        descriptor.getCategoryName(),
                        "system");
                // Ensure the type is of the correct type (try a cast!)
                IntPolicyType intType = (IntPolicyType) descriptor.getPolicyType();

                // ------------------------------------------------------------
                // range
                // ------------------------------------------------------------
                descriptor = (DefaultPolicyDescriptor)
                        accessor.retrievePolicyDescriptor(
                                connection, "localsec", locale);
                // Ensure the names and help match as expected
                assertEquals("Descriptive name should match (range)",
                        descriptor.getPolicyDescriptiveName(),
                        "Local data security");
                assertEquals("Help should match (range)",
                        descriptor.getPolicyHelp(),
                        "An indication of the level of security built into the" +
                        " device for securing user data");
                assertEquals("Category should match (range)",
                        descriptor.getCategoryName(),
                        "security");
                // Ensure the type is of the correct type (try a cast!)
                RangePolicyType rangeType = (RangePolicyType) descriptor.getPolicyType();
                assertEquals("Max should match", 100, rangeType.getMaxInclusive());
                assertEquals("Min should match", -1, rangeType.getMinInclusive());

                // ------------------------------------------------------------
                // selection
                // ------------------------------------------------------------
                descriptor = (DefaultPolicyDescriptor)
                        accessor.retrievePolicyDescriptor(
                                connection, "J2MEconf", locale);
                // Ensure the names and help match as expected
                assertEquals("Descriptive name should match (selection)",
                        descriptor.getPolicyDescriptiveName(),
                        "J2ME configuration");
                assertEquals("Help should match (selection)",
                        descriptor.getPolicyHelp(),
                        "Describes the specific J2ME configuration implemented" +
                        " on the device");
                assertEquals("Category should match (selection)",
                        descriptor.getCategoryName(),
                        "system");
                // Ensure the type is of the correct type (try a cast!)
                SelectionPolicyType selectionType =
                        (SelectionPolicyType) descriptor.getPolicyType();
                String[] expected = new String[]{"none", "CLDC-1.0", "CDC-1.0"};
                List keywords = selectionType.getKeywords();
                int size = keywords.size();
                for (int i = 0; i < size; i++) {
                    assertEquals("Keyword " + i + " should match",
                            (String) keywords.get(i),
                            expected[i]);
                }

                // ------------------------------------------------------------
                // text
                // ------------------------------------------------------------
                descriptor = (DefaultPolicyDescriptor)
                        accessor.retrievePolicyDescriptor(
                                connection, "cpumfgr", locale);
                // Ensure the names and help match as expected
                assertEquals("Descriptive name should match (text)",
                        descriptor.getPolicyDescriptiveName(),
                        "Processor manufacturer");
                assertEquals("Help should match (text)",
                        descriptor.getPolicyHelp(),
                        "The manufacturer of the device processor");
                assertEquals("Category should match (text)",
                        descriptor.getCategoryName(),
                        "system");
                // Ensure the type is of the correct type (try a cast!)
                TextPolicyType textType = (TextPolicyType) descriptor.getPolicyType();

                // ------------------------------------------------------------
                // structure
                // ------------------------------------------------------------
                descriptor = (DefaultPolicyDescriptor)
                        accessor.retrievePolicyDescriptor(connection,
                                "protocol.wml.emulate.bigTag", locale);
                // Ensure the names and help match as expected
                assertEquals("Descriptive name should match (structure)",
                        descriptor.getPolicyDescriptiveName(),
                        "Emulate WML big tag");
                assertEquals("Help should match (structure)",
                        descriptor.getPolicyHelp(),
                        "Controls markup or textual substitution for the WML" +
                        " <big> element");
                assertEquals("Category should match (structure)",
                        descriptor.getCategoryName(),
                        "protocol");
                // Ensure the type is of the correct type (try a cast!)
                StructurePolicyType structureType =
                        (StructurePolicyType) descriptor.getPolicyType();

                Map fields = structureType.getFieldTypes();
                Set keys = fields.keySet();
                String[] expectedKeys = new String[]{
                    "enable", "prefix", "suffix", "altTag"
                };
                size = expectedKeys.length;
                for (int i = 0; i < size; i++) {
                    assertTrue("Key " + i + " should be in the key set",
                            keys.contains(expectedKeys[i]));
                    assertNotNull("Key " + i + " should map to a non-null value",
                            fields.get(expectedKeys[i]));
                }

                // ------------------------------------------------------------
                // ordered set
                // ------------------------------------------------------------
                descriptor = (DefaultPolicyDescriptor)
                        accessor.retrievePolicyDescriptor(
                                connection, "protocol", locale);
                // Ensure the names and help match as expected
                assertEquals("Descriptive name should match (ordered set)",
                        descriptor.getPolicyDescriptiveName(),
                        "Protocol");
                assertEquals("Help should match (ordered set)",
                        descriptor.getPolicyHelp(),
                        "The protocol (markup language) to be used to" +
                        " communicate with the browser");
                assertEquals("Category should match (ordered set)",
                        descriptor.getCategoryName(),
                        "browser");
                // Ensure the type is of the correct type (try a cast!)
                OrderedSetPolicyType orderedSetType =
                        (OrderedSetPolicyType) descriptor.getPolicyType();
                PolicyType memberType = orderedSetType.getMemberPolicyType();
                assertTrue("Type of set values should match",
                        memberType instanceof SelectionPolicyType);

                // ------------------------------------------------------------
                // unordered set
                // ------------------------------------------------------------
                descriptor = (DefaultPolicyDescriptor)
                        accessor.retrievePolicyDescriptor(connection,
                                "UAProf.Push-Accept", locale);
                // Ensure the names and help match as expected
                assertEquals("Descriptive name should match (unordered set)",
                        descriptor.getPolicyDescriptiveName(),
                        "Push content types supported");
                assertEquals("Help should match (unordered set)",
                        descriptor.getPolicyHelp(),
                        "List of content types the device supports for push");
                assertEquals("Category should match (unordered set)",
                        descriptor.getCategoryName(),
                        "message");
                // Ensure the type is of the correct type (try a cast!)
                UnorderedSetPolicyType unorderedSetType =
                        (UnorderedSetPolicyType) descriptor.getPolicyType();
                memberType = unorderedSetType.getMemberPolicyType();
                assertTrue("Type of set values should match",
                        memberType instanceof TextPolicyType);

                {
                    // -------------------------------------------------------
                    // fallback (fake)
                    // -------------------------------------------------------
                    descriptor = (DefaultPolicyDescriptor)
                            accessor.retrievePolicyDescriptor(connection,
                                    "fallback", locale);
                    // Ensure the names and help match as expected
                    assertEquals("Descriptive name should match (fallback)",
                            descriptor.getPolicyDescriptiveName(), "fallback");
                    assertEquals("Help should match (fallback)",
                            descriptor.getPolicyHelp(), "fallback");
                    assertEquals("Category should match (fallback)",
                            descriptor.getCategoryName(),
                            "identification");
                    // Ensure the type is of the correct type
                    assertTrue(descriptor.getPolicyType() instanceof
                            TextPolicyType);
                }
            }
        });
View Full Code Here

TOP

Related Classes of com.volantis.devrep.repository.impl.devices.policy.DefaultPolicyDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.