Package org.fao.geonet.domain

Examples of org.fao.geonet.domain.SchematronRequirement


                List<SchematronCriteriaGroup> criteriaGroups = criteriaGroupRepository.findAllById_SchematronId(schematron.getId());

                //Loop through all criteria to see if apply schematron
                //if any criteria does not apply, do not apply at all (AND)
                SchematronRequirement requirement = SchematronRequirement.DISABLED;
                for (SchematronCriteriaGroup criteriaGroup : criteriaGroups) {
                    List<SchematronCriteria> criterias = criteriaGroup.getCriteria();
                    boolean apply = false;
                    for(SchematronCriteria criteria : criterias) {
                        boolean tmpApply = criteria.accepts(_applicationContext, metadataId, md, metadataSchema.getSchemaNS());

                        if(!tmpApply) {
                            apply = false;
                            break;
                        } else {
                            apply = true;
                        }

                    }

                    if (apply) {
                        if(Log.isDebugEnabled(Geonet.DATA_MANAGER)) {
                            Log.debug(Geonet.DATA_MANAGER, " - Schematron group is accepted:" + criteriaGroup.getId().getName() + " for schematron: "+schematron.getRuleName());
                        }
                        requirement = requirement.highestRequirement(criteriaGroup.getRequirement());
                    } else {
                        requirement = SchematronRequirement.DISABLED;
                    }
                }

                if(requirement != SchematronRequirement.DISABLED) {
                    if(Log.isDebugEnabled(Geonet.DATA_MANAGER)) {
                        Log.debug(Geonet.DATA_MANAGER, " - rule:" + rule);
                    }


                    Integer ifNotValid = (requirement == SchematronRequirement.REQUIRED ? 0 : 2);

                    String ruleId = schematron.getRuleName();

                    Element report = new Element("report", Edit.NAMESPACE);
                    report.setAttribute("rule", ruleId,
                            Edit.NAMESPACE);
                    report.setAttribute("displayPriority", ""+schematron.getDisplayPriority(),
                            Edit.NAMESPACE);
                    report.setAttribute("dbident", dbident,
                            Edit.NAMESPACE);
                    report.setAttribute("required", requirement.toString(), Edit.NAMESPACE);

                    try {
                        Map<String,Object> params = new HashMap<String,Object>();
                        params.put("lang", lang);
                        params.put("rule", ruleId);
View Full Code Here


    @Test
    public void testExecEditRequirement() throws Exception {
        ServiceContext context = createServiceContext();
        loginAsAdmin(context);

        SchematronRequirement newRequirement = SchematronRequirement.DISABLED;
        if (_group1_Name1_SchematronId1.getRequirement() == SchematronRequirement.DISABLED) {
            newRequirement = SchematronRequirement.REQUIRED;
        }
        Element editParams = createParams(
                read(SchematronCriteriaGroupService.PARAM_GROUP_NAME, _group1_Name1_SchematronId1.getId().getName()),
                read(SchematronCriteriaGroupService.PARAM_SCHEMATRON_ID, _group1_Name1_SchematronId1.getId().getSchematronId()),
                read(SchematronCriteriaGroupService.PARAM_REQUIREMENT, newRequirement)
        );

        Element result = createService(EDIT).exec(editParams, context);
        assertEquals("ok", result.getName());

        Element listParams = createParams(
                read(SchematronCriteriaGroupService.PARAM_GROUP_NAME, _group1_Name1_SchematronId1.getId().getName()),
                read(SchematronCriteriaGroupService.PARAM_SCHEMATRON_ID, _group1_Name1_SchematronId1.getId().getSchematronId())
        );

        result = createService(LIST).exec(listParams, context);
        assertEquals(1, result.getChildren().size());

        assertEquals(newRequirement.name(), result.getChild(GeonetEntity.RECORD_EL_NAME).getChildText("requirement"));

    }
View Full Code Here

    public void testExecEditNameAndRequirement() throws Exception {
        ServiceContext context = createServiceContext();
        loginAsAdmin(context);


        SchematronRequirement newRequirement = SchematronRequirement.REPORT_ONLY;
        if (_group1_Name1_SchematronId1.getRequirement() == newRequirement) {
            newRequirement = SchematronRequirement.REQUIRED;
        }
        final String newGroupName = "newGroupName";
        Element editParams = createParams(
                read(SchematronCriteriaGroupService.PARAM_GROUP_NAME, _group1_Name1_SchematronId1.getId().getName()),
                read(SchematronCriteriaGroupService.PARAM_SCHEMATRON_ID, _group1_Name1_SchematronId1.getId().getSchematronId()),
                read(SchematronCriteriaGroupService.PARAM_NEW_GROUP_NAME, newGroupName),
                read(SchematronCriteriaGroupService.PARAM_REQUIREMENT, newRequirement)

        );

        Element result = createService(EDIT).exec(editParams, context);
        assertEquals("ok", result.getName());

        Element listParamsOldName = createParams(
                read(SchematronCriteriaGroupService.PARAM_GROUP_NAME, _group1_Name1_SchematronId1.getId().getName()),
                read(SchematronCriteriaGroupService.PARAM_SCHEMATRON_ID, _group1_Name1_SchematronId1.getId().getSchematronId())
        );

        result = createService(EXISTS).exec(listParamsOldName, context);
        assertEquals(""+false, result.getText());

        Element listParamsNewName = createParams(
                read(SchematronCriteriaGroupService.PARAM_GROUP_NAME, newGroupName),
                read(SchematronCriteriaGroupService.PARAM_SCHEMATRON_ID, _group1_Name1_SchematronId1.getId().getSchematronId())
        );

        result = createService(LIST).exec(listParamsNewName, context);
        assertEquals(1, result.getChildren().size());

        assertEquals(newRequirement.toString(), result.getChild(GeonetEntity.RECORD_EL_NAME).getChildText("requirement"));
        assertEquals(_group1_Name1_SchematronId1.getCriteria().size(), result.getChild(GeonetEntity.RECORD_EL_NAME).getChild("criteria").getChildren().size());
    }
View Full Code Here

TOP

Related Classes of org.fao.geonet.domain.SchematronRequirement

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.