Search in sources :

Example 71 with SortedSet

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;
}
Also used : HashMap(java.util.HashMap) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) SortedSet(java.util.SortedSet)

Example 72 with SortedSet

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;
}
Also used : HashMap(java.util.HashMap) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) SortedSet(java.util.SortedSet)

Example 73 with SortedSet

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;
}
Also used : ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) SortedSet(java.util.SortedSet) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) ArrayList(java.util.ArrayList) List(java.util.List) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean)

Example 74 with SortedSet

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;
}
Also used : SortedSet(java.util.SortedSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) PackageElement(javax.lang.model.element.PackageElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) PrintWriter(java.io.PrintWriter) IOException(java.io.IOException) PackageElement(javax.lang.model.element.PackageElement) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer)

Example 75 with SortedSet

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);
    }
}
Also used : SortedSet(java.util.SortedSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) ArrayList(java.util.ArrayList) SSOException(com.iplanet.sso.SSOException) SortedSet(java.util.SortedSet) Collator(java.text.Collator) ServiceSchema(com.sun.identity.sm.ServiceSchema) ServiceConfig(com.sun.identity.sm.ServiceConfig) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator)

Aggregations

SortedSet (java.util.SortedSet)127 TreeSet (java.util.TreeSet)49 Iterator (java.util.Iterator)43 HashMap (java.util.HashMap)24 NavigableSet (java.util.NavigableSet)22 ArrayList (java.util.ArrayList)20 Map (java.util.Map)20 List (java.util.List)19 Set (java.util.Set)19 TreeMap (java.util.TreeMap)18 HashSet (java.util.HashSet)15 Test (org.junit.Test)13 IOException (java.io.IOException)12 Collection (java.util.Collection)10 Comparator (java.util.Comparator)7 LinkedHashMap (java.util.LinkedHashMap)7 LinkedList (java.util.LinkedList)5 SolverException (cbit.vcell.solver.SolverException)3 TestStringSortedSetGenerator (com.google.common.collect.testing.TestStringSortedSetGenerator)3 File (java.io.File)3