use of java.util.SortedSet in project OpenClinica by OpenClinica.
the class EventDefinitionCRFDAO method buildEventDefinitionCRFListByStudyEventDefinitionForStudy.
public Map<Integer, SortedSet<EventDefinitionCRFBean>> buildEventDefinitionCRFListByStudyEventDefinitionForStudy(Integer studySubjectId) {
// <== Must be called first
this.setTypesExpected();
HashMap<Integer, Object> param = new HashMap<Integer, Object>();
int i = 1;
param.put(i++, studySubjectId);
List selectResult = select(digester.getQuery("buildEventDefinitionCRFListByStudyEventDefinitionForStudy"), param);
Map<Integer, SortedSet<EventDefinitionCRFBean>> result = new HashMap<Integer, SortedSet<EventDefinitionCRFBean>>();
Iterator it = selectResult.iterator();
while (it.hasNext()) {
EventDefinitionCRFBean bean = (EventDefinitionCRFBean) this.getEntityFromHashMap((HashMap) it.next());
Integer studyEventDefinitionId = bean.getStudyEventDefinitionId();
if (!result.containsKey(studyEventDefinitionId)) {
result.put(studyEventDefinitionId, new TreeSet<EventDefinitionCRFBean>(new EventDefinitionCRFComparator()));
}
result.get(studyEventDefinitionId).add(bean);
}
return result;
}
use of java.util.SortedSet in project OpenClinica by OpenClinica.
the class EventDefinitionCRFDAO method buildEventDefinitionCRFListByStudyEventDefinition.
/**
* Loads all {@link EventDefinitionCRFBean} associated to the list of
* {@link StudyEventDefinitionBean}
*
* @return
*/
public Map<Integer, SortedSet<EventDefinitionCRFBean>> buildEventDefinitionCRFListByStudyEventDefinition(Integer studySubjectId, Integer siteId, Integer parentStudyId) {
// <== Must be called first
this.setTypesExpected();
HashMap<Integer, Object> param = new HashMap<Integer, Object>();
int i = 1;
param.put(i++, studySubjectId);
param.put(i++, siteId);
param.put(i++, parentStudyId);
param.put(i++, studySubjectId);
param.put(i++, siteId);
List selectResult = select(digester.getQuery("buildEventDefinitionCRFListByStudyEventDefinition"), param);
Map<Integer, SortedSet<EventDefinitionCRFBean>> result = new HashMap<Integer, SortedSet<EventDefinitionCRFBean>>();
Iterator it = selectResult.iterator();
while (it.hasNext()) {
EventDefinitionCRFBean bean = (EventDefinitionCRFBean) this.getEntityFromHashMap((HashMap) it.next());
Integer studyEventDefinitionId = bean.getStudyEventDefinitionId();
if (!result.containsKey(studyEventDefinitionId)) {
result.put(studyEventDefinitionId, new TreeSet<EventDefinitionCRFBean>(new EventDefinitionCRFComparator()));
}
result.get(studyEventDefinitionId).add(bean);
}
return result;
}
use of java.util.SortedSet in project OpenClinica by OpenClinica.
the class StudySubjectServiceImpl method getDisplayStudyEventsForStudySubject.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<DisplayStudyEventBean> getDisplayStudyEventsForStudySubject(StudySubjectBean studySubject, UserAccountBean userAccount, StudyUserRoleBean currentRole) {
StudyEventDAO studyEventDao = new StudyEventDAO(dataSource);
StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(dataSource);
StudyDAO studyDao = new StudyDAO(dataSource);
EventDefinitionCRFDAO eventDefinitionCrfDao = new EventDefinitionCRFDAO(dataSource);
EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
CRFDAO crfDao = new CRFDAO(dataSource);
FormLayoutDAO formLayoutDAO = new FormLayoutDAO(dataSource);
ArrayList events = studyEventDao.findAllByStudySubject(studySubject);
Map<Integer, StudyEventDefinitionBean> eventDefinitionByEvent = studyEventDefinitionDao.findByStudySubject(studySubject.getId());
StudyBean study = (StudyBean) studyDao.findByPK(studySubject.getStudyId());
Map<Integer, SortedSet<EventDefinitionCRFBean>> eventDefinitionCrfByStudyEventDefinition;
if (study.getParentStudyId() < 1) {
// Is a study
eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinitionForStudy(studySubject.getId());
} else {
// Is a site
eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinition(studySubject.getId(), study.getId(), study.getParentStudyId());
}
Map<Integer, SortedSet<EventCRFBean>> eventCrfListByStudyEvent = eventCrfDao.buildEventCrfListByStudyEvent(studySubject.getId());
Map<Integer, Integer> maxOrdinalByStudyEvent = studyEventDefinitionDao.buildMaxOrdinalByStudyEvent(studySubject.getId());
Set<Integer> nonEmptyEventCrf = eventCrfDao.buildNonEmptyEventCrfIds(studySubject.getId());
Map<Integer, FormLayoutBean> formLayoutById = formLayoutDAO.buildFormLayoutById(studySubject.getId());
Map<Integer, CRFBean> crfById = crfDao.buildCrfById(studySubject.getId());
ArrayList<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
for (int i = 0; i < events.size(); i++) {
StudyEventBean event = (StudyEventBean) events.get(i);
StudyEventDefinitionBean sed = eventDefinitionByEvent.get(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
List eventDefinitionCRFs = new ArrayList((eventDefinitionCrfByStudyEventDefinition.containsKey(sed.getId()) ? eventDefinitionCrfByStudyEventDefinition.get(sed.getId()) : Collections.EMPTY_LIST));
List eventCRFs = new ArrayList((eventCrfListByStudyEvent.containsKey(event.getId())) ? eventCrfListByStudyEvent.get(event.getId()) : Collections.EMPTY_LIST);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs((ArrayList<DisplayEventCRFBean>) getDisplayEventCRFs(eventCRFs, userAccount, currentRole, event.getSubjectEventStatus(), study, nonEmptyEventCrf, formLayoutById, crfById, event.getStudyEventDefinitionId(), eventDefinitionCRFs));
ArrayList<DisplayEventDefinitionCRFBean> al = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus(), nonEmptyEventCrf, formLayoutById, crfById);
populateUncompletedCRFsWithCRFAndVersions(al, formLayoutById, crfById);
de.setUncompletedCRFs(al);
// de.setMaximumSampleOrdinal(studyEventDao.getMaxSampleOrdinal(sed,
// studySubject));
de.setMaximumSampleOrdinal(maxOrdinalByStudyEvent.get(event.getStudyEventDefinitionId()));
displayEvents.add(de);
// event.setEventCRFs(createAllEventCRFs(eventCRFs,
// eventDefinitionCRFs));
}
return displayEvents;
}
use of java.util.SortedSet in project dukescript-presenters by dukescript.
the class MessagesProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
return false;
}
Map<String, Set<Element>> /*package*/
annotatedElementsByPackage = new HashMap<String, Set<Element>>();
for (Element e : roundEnv.getElementsAnnotatedWith(Messages.class)) {
Messages messages = e.getAnnotation(Messages.class);
if (messages == null) {
// bug in java.source, apparently; similar to #195983
continue;
}
String pkg = findPackage(e);
Set<Element> annotatedElements = annotatedElementsByPackage.get(pkg);
if (annotatedElements == null) {
annotatedElements = new HashSet<Element>();
annotatedElementsByPackage.put(pkg, annotatedElements);
}
annotatedElements.add(e);
}
PACKAGE: for (Map.Entry<String, Set<Element>> packageEntry : annotatedElementsByPackage.entrySet()) {
String pkg = packageEntry.getKey();
Set<Element> annotatedElements = packageEntry.getValue();
PackageElement pkgE = processingEnv.getElementUtils().getPackageElement(pkg);
if (pkgE != null) {
Set<Element> unscannedTopElements = new HashSet<Element>();
unscannedTopElements.add(pkgE);
try {
unscannedTopElements.addAll(pkgE.getEnclosedElements());
} catch (/*NullPointerException,BadClassFile*/
RuntimeException x) {
// #196556
processingEnv.getMessager().printMessage(Kind.WARNING, "#196556: reading " + pkg + " failed with " + x + " in " + x.getStackTrace()[0] + "; do a clean build!");
}
unscannedTopElements.removeAll(roundEnv.getRootElements());
addToAnnotatedElements(unscannedTopElements, annotatedElements);
} else {
processingEnv.getMessager().printMessage(Kind.WARNING, "Could not check for other source files in " + pkg);
}
Map<String, String> /*value*/
pairs = new HashMap<String, String>();
Map<String, Element> /*identifier*/
identifiers = new HashMap<String, Element>();
Map<String, String> /*simplename*/
compilationUnits = new HashMap<String, String>();
for (Element e : annotatedElements) {
String simplename = findCompilationUnitName(e);
for (String keyValue : e.getAnnotation(Messages.class).value()) {
int i = keyValue.indexOf('=');
if (i == -1) {
processingEnv.getMessager().printMessage(Kind.ERROR, "Bad key=value: " + keyValue, e);
continue;
}
String key = keyValue.substring(0, i);
if (key.isEmpty() || !key.equals(key.trim())) {
processingEnv.getMessager().printMessage(Kind.ERROR, "Whitespace not permitted in key: " + keyValue, e);
continue;
}
Element original = identifiers.put(key, e);
if (original != null) {
processingEnv.getMessager().printMessage(Kind.ERROR, "Duplicate key: " + key, e);
processingEnv.getMessager().printMessage(Kind.ERROR, "Duplicate key: " + key, original);
// do not generate anything
continue PACKAGE;
}
String value = keyValue.substring(i + 1);
if (value.startsWith("$")) {
value = processingEnv.getOptions().get(value.substring(1));
}
pairs.put(key, value);
compilationUnits.put(key, simplename);
}
}
Element[] elements = new HashSet<Element>(identifiers.values()).toArray(new Element[0]);
try {
Map<String, Method> /*identifier*/
methods = new TreeMap<String, Method>();
for (Map.Entry<String, String> entry2 : pairs.entrySet()) {
String key = entry2.getKey();
String value = entry2.getValue();
SortedSet<Subst> substitutions = new TreeSet<Subst>();
int i;
for (i = 0; ; i++) {
final String subst = "@" + (i + 1);
int pos = -1;
for (; ; ) {
int where = value.indexOf(subst, pos + 1);
if (where == -1) {
break;
}
substitutions.add(new Subst(where, subst.length(), i));
pos = where;
}
if (pos == -1) {
break;
}
}
methods.put(key, new Method(key, substitutions, value));
}
String fqn = pkg + ".Strings";
Writer w = processingEnv.getFiler().createSourceFile(fqn, elements).openWriter();
StringBuilder buf = new StringBuilder();
for (Method method : methods.values()) {
method.at = buf.length();
buf.append(method.text);
}
String chunk = processingEnv.getOptions().get("stringSize");
String seedStr = processingEnv.getOptions().get("stringSeed");
int length = buf.length();
long seed = 0;
if (chunk != null && seedStr != null) {
length = Integer.parseInt(chunk);
if ("now".equals(seedStr)) {
seed = System.currentTimeMillis();
} else {
seed = Long.parseLong(seedStr);
}
processingEnv.getMessager().printMessage(Kind.NOTE, "Using string size " + length + " and seed " + seed);
}
Buffer b = new Buffer(buf, length, seed);
try {
PrintWriter pw = new PrintWriter(w);
pw.println("package " + pkg + ";");
pw.println("/** Localizable strings for {@link " + pkg + "}. */");
pw.println("@javax.annotation.Generated(value=\"" + MessagesProcessor.class.getName() + "\")");
pw.println("class Strings {");
for (Method method : methods.values()) {
pw.print(method.toString(b));
}
pw.println(" private void Strings() {}");
pw.print(" private static final String text = \"");
pw.print(b.buf.toString().replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n\" + \n\""));
pw.println("\";\n");
pw.println("}");
pw.flush();
pw.close();
} finally {
w.close();
}
} catch (IOException x) {
processingEnv.getMessager().printMessage(Kind.ERROR, "Could not generate files: " + x, elements[0]);
}
}
return true;
}
use of java.util.SortedSet in project OpenAM by OpenRock.
the class SubConfigMeta method getSubConfigurationsFromConfig.
private void getSubConfigurationsFromConfig() {
try {
String[] params = { serviceName, parentConfig.getComponentName() };
amModel.logEvent("ATTEMPT_READ_GLOBAL_SUB_CONFIGURATION_NAMES", params);
Set names = parentConfig.getSubConfigNames();
if ((names != null) && !names.isEmpty()) {
Collator collator = Collator.getInstance(amModel.getUserLocale());
SortedSet set = new TreeSet(new SMSubConfigComparator(collator));
for (Iterator iter = names.iterator(); iter.hasNext(); ) {
String name = (String) iter.next();
ServiceConfig conf = parentConfig.getSubConfig(name);
String schemaID = conf.getSchemaID();
if (globalSubSchemaNames.contains(schemaID)) {
String displayType = (String) mapServiceSchemaNameToL10NName.get(schemaID);
String localizedName = getLocalizedString(CollectionHelper.getMapAttr(conf.getAttributes(), SMSUtils.I18N_KEY));
ServiceSchema schema = corrSchema.getSubSchema(schemaID);
set.add(new SMSubConfig(conf.getComponentName(), name, displayType, localizedName, schema.isHiddenInConfigUI()));
if (singleInstanceGlobalSubSchemas.contains(schemaID)) {
creatableGlobalSubSchemas.remove(schemaID);
}
}
}
if (!set.isEmpty()) {
globalSubConfigurations = new ArrayList(set.size());
globalSubConfigurations.addAll(set);
}
}
amModel.logEvent("SUCCEED_READ_GLOBAL_SUB_CONFIGURATION_NAMES", params);
} catch (SSOException e) {
String[] paramsEx = { serviceName, parentConfig.getComponentName(), amModel.getErrorString(e) };
amModel.logEvent("SSO_EXCEPTION_READ_GLOBAL_SUB_CONFIGURATION_NAMES", paramsEx);
AMModelBase.debug.error("SubConfigMeta.getSubConfigurations", e);
} catch (SMSException e) {
String[] paramsEx = { serviceName, parentConfig.getComponentName(), amModel.getErrorString(e) };
amModel.logEvent("SMS_EXCEPTION_READ_GLOBAL_SUB_CONFIGURATION_NAMES", paramsEx);
AMModelBase.debug.error("SubConfigMeta.getSubConfigurations", e);
}
}
Aggregations