<commit_before>package com.krishagni.catissueplus.core.de.services.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.krishagni.catissueplus.core.common.PlusTransactional;
import com.krishagni.catissueplus.core.common.errors.OpenSpecimenException;
import com.krishagni.catissueplus.core.de.domain.FormErrorCode;
import com.krishagni.catissueplus.core.importer.domain.ObjectSchema;
import com.krishagni.catissueplus.core.importer.domain.ObjectSchema.Field;
import com.krishagni.catissueplus.core.importer.domain.ObjectSchema.Record;
import com.krishagni.catissueplus.core.importer.services.ObjectSchemaBuilder;

import edu.common.dynamicextensions.domain.nui.Container;
import edu.common.dynamicextensions.domain.nui.Control;
import edu.common.dynamicextensions.domain.nui.MultiSelectControl;
import edu.common.dynamicextensions.domain.nui.SubFormControl;

public class ExtensionSchemaBuilder implements ObjectSchemaBuilder {

	@Override
	@PlusTransactional	
	public ObjectSchema getObjectSchema(Map<String, Object> params) {
		String formName = (String)params.get("formName");
		if (StringUtils.isBlank(formName)) {
			throw OpenSpecimenException.userError(FormErrorCode.NAME_REQUIRED);
		}
		
		String entityType = (String)params.get("entityType");
		if (StringUtils.isBlank(entityType)) {
			throw OpenSpecimenException.userError(FormErrorCode.ENTITY_TYPE_REQUIRED);
		}
		
		Container form = Container.getContainer(formName);
		if (form == null) {
			throw OpenSpecimenException.userError(FormErrorCode.NOT_FOUND);
		}
		
		return getObjectSchema(form, entityType);
	}
	
	private ObjectSchema getObjectSchema(Container form, String entityType) {
		Record record = new Record();  
		
		List<Field> fields = new ArrayList<Field>();
		fields.add(getField("recordId", "Record ID"));
		
		if (entityType.equals("Participant")) {
			fields.add(getField("cpShortTitle", "Collection Protocol"));
			fields.add(getField("ppid", "PPID"));
		} else if (entityType.equals("SpecimenCollectionGroup")) {
			fields.add(getField("visitName", "Visit Name"));
		} else if (entityType.equals("Specimen") || entityType.equals("SpecimenEvent")) {
			fields.add(getField("specimenLabel", "Specimen Label"));
		}
		
		record.setFields(fields);
		
		Record formValueMap = getFormRecord(form);
		formValueMap.setAttribute("formValueMap");
		record.setSubRecords(Collections.singletonList(formValueMap));
		
		ObjectSchema objectSchema = new ObjectSchema();
		objectSchema.setRecord(record);
		return objectSchema;
	}
	
	private Record getFormRecord(Container form) {
		List<Field> fields = new ArrayList<Field>();
		List<Record> subRecords = new ArrayList<Record>();
		
		for (Control ctrl: form.getAllControls()) {
			if (ctrl instanceof SubFormControl) {
				subRecords.add(getSubRecord((SubFormControl)ctrl));
			} else {
				fields.add(getField(ctrl));
			}
		}
		
		Record record = new Record();
		record.setFields(fields);
		record.setSubRecords(subRecords);
		record.setName(form.getName());
		return record;
	}
	
	
	private Field getField(String attr, String caption) {
		return getField(attr, caption, false);		
	}
	
	private Field getField(Control ctrl) {
		return getField(
				ctrl.getUserDefinedName(),
				ctrl.getCaption(),
				ctrl instanceof MultiSelectControl);
	}
	
	private Record getSubRecord(SubFormControl ctrl) {
		Record subRec = getFormRecord(ctrl.getSubContainer());
		subRec.setAttribute(ctrl.getUserDefinedName());
		subRec.setCaption(ctrl.getCaption());
		subRec.setMultiple(true);
		return subRec;		
	}
	
	private Field getField(String attr, String caption, boolean multiple) {
		Field field = new Field();
		field.setAttribute(attr);
		field.setCaption(caption);
		field.setMultiple(multiple);
		return field;
	}	
}
<commit_msg>Fixed minor operator spacing issue<commit_after>package com.krishagni.catissueplus.core.de.services.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.krishagni.catissueplus.core.common.PlusTransactional;
import com.krishagni.catissueplus.core.common.errors.OpenSpecimenException;
import com.krishagni.catissueplus.core.de.domain.FormErrorCode;
import com.krishagni.catissueplus.core.importer.domain.ObjectSchema;
import com.krishagni.catissueplus.core.importer.domain.ObjectSchema.Field;
import com.krishagni.catissueplus.core.importer.domain.ObjectSchema.Record;
import com.krishagni.catissueplus.core.importer.services.ObjectSchemaBuilder;

import edu.common.dynamicextensions.domain.nui.Container;
import edu.common.dynamicextensions.domain.nui.Control;
import edu.common.dynamicextensions.domain.nui.MultiSelectControl;
import edu.common.dynamicextensions.domain.nui.SubFormControl;

public class ExtensionSchemaBuilder implements ObjectSchemaBuilder {

	@Override
	@PlusTransactional	
	public ObjectSchema getObjectSchema(Map<String, Object> params) {
		String formName = (String)params.get("formName");
		if (StringUtils.isBlank(formName)) {
			throw OpenSpecimenException.userError(FormErrorCode.NAME_REQUIRED);
		}
		
		String entityType = (String)params.get("entityType");
		if (StringUtils.isBlank(entityType)) {
			throw OpenSpecimenException.userError(FormErrorCode.ENTITY_TYPE_REQUIRED);
		}
		
		Container form = Container.getContainer(formName);
		if (form == null) {
			throw OpenSpecimenException.userError(FormErrorCode.NOT_FOUND);
		}
		
		return getObjectSchema(form, entityType);
	}
	
	private ObjectSchema getObjectSchema(Container form, String entityType) {
		Record record = new Record();  
		
		List<Field> fields = new ArrayList<Field>();
		fields.add(getField("recordId", "Record ID"));
		
		if (entityType.equals("Participant")) {
			fields.add(getField("cpShortTitle", "Collection Protocol"));
			fields.add(getField("ppid", "PPID"));
		} else if (entityType.equals("SpecimenCollectionGroup")) {
			fields.add(getField("visitName", "Visit Name"));
		} else if (entityType.equals("Specimen") || entityType.equals("SpecimenEvent")) {
			fields.add(getField("specimenLabel", "Specimen Label"));
		}
		
		record.setFields(fields);
		
		Record formValueMap = getFormRecord(form);
		formValueMap.setAttribute("formValueMap");
		record.setSubRecords(Collections.singletonList(formValueMap));
		
		ObjectSchema objectSchema = new ObjectSchema();
		objectSchema.setRecord(record);
		return objectSchema;
	}
	
	private Record getFormRecord(Container form) {
		List<Field> fields = new ArrayList<Field>();
		List<Record> subRecords = new ArrayList<Record>();
		
		for (Control ctrl : form.getAllControls()) {
			if (ctrl instanceof SubFormControl) {
				subRecords.add(getSubRecord((SubFormControl)ctrl));
			} else {
				fields.add(getField(ctrl));
			}
		}
		
		Record record = new Record();
		record.setFields(fields);
		record.setSubRecords(subRecords);
		record.setName(form.getName());
		return record;
	}
	
	
	private Field getField(String attr, String caption) {
		return getField(attr, caption, false);		
	}
	
	private Field getField(Control ctrl) {
		return getField(
				ctrl.getUserDefinedName(),
				ctrl.getCaption(),
				ctrl instanceof MultiSelectControl);
	}
	
	private Record getSubRecord(SubFormControl ctrl) {
		Record subRec = getFormRecord(ctrl.getSubContainer());
		subRec.setAttribute(ctrl.getUserDefinedName());
		subRec.setCaption(ctrl.getCaption());
		subRec.setMultiple(true);
		return subRec;		
	}
	
	private Field getField(String attr, String caption, boolean multiple) {
		Field field = new Field();
		field.setAttribute(attr);
		field.setCaption(caption);
		field.setMultiple(multiple);
		return field;
	}	
}

{'fraction_non_alphanumeric': 0.11798188874514877, 'fraction_numerical': 0.0, 'mean_word_length': 5.5295608108108105, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '423658', 'n_tokens_mistral': 2598, 'n_tokens_neox': 2356, 'n_words': 410}