Example usage for java.util Vector clear

List of usage examples for java.util Vector clear

Introduction

In this page you can find the example usage for java.util Vector clear.

Prototype

public void clear() 

Source Link

Document

Removes all of the elements from this Vector.

Usage

From source file:de.mpg.escidoc.pubman.easySubmission.EasySubmission.java

/**
 * Handles the import from an external ingestion sources.
 * /*from w  ww .  ja  va 2  s.co m*/
 * @return navigation String
 */
public String harvestData() {
    FileVO fileVO = new FileVO();
    Vector<FileVO> fileVOs = new Vector<FileVO>();
    String fetchedItem = null;
    String service = this.getEasySubmissionSessionBean().getCurrentExternalServiceType();
    PubItemVO itemVO = null;
    byte[] fetchedItemByte = null;
    DataHandlerBean dataHandler = new DataHandlerBean();
    // Fetch data from external system
    if (EasySubmissionSessionBean.IMPORT_METHOD_EXTERNAL
            .equals(this.getEasySubmissionSessionBean().getImportMethod())) {
        if (getServiceID() == null || "".equals(getServiceID())) {
            warn(getMessage("easy_submission_external_service_no_id"));
            return null;
        }
        try {
            // Harvest metadata
            logger.debug("HarvestData: " + this.getEasySubmissionSessionBean().getCurrentExternalServiceType()
                    + ": " + getServiceID());
            fetchedItemByte = dataHandler.doFetch(service, getServiceID(), this.INTERNAL_MD_FORMAT);
            fetchedItem = new String(fetchedItemByte, 0, fetchedItemByte.length, "UTF8");
            // Harvest full text
            if (this.getEasySubmissionSessionBean().isFulltext() && ((!this.getEasySubmissionSessionBean()
                    .getRadioSelectFulltext().equals(this.getEasySubmissionSessionBean().FULLTEXT_NONE))
                    && !fetchedItem.equals("")) && !service.equalsIgnoreCase("escidoc")) {
                DataSourceVO source = this.dataSourceHandler.getSourceByName(service);
                Vector<FullTextVO> ftFormats = source.getFtFormats();
                FullTextVO fulltext = new FullTextVO();
                Vector<String> formats = new Vector<String>();
                // Get DEFAULT full text version from source
                if (this.getEasySubmissionSessionBean().getRadioSelectFulltext()
                        .equals(this.getEasySubmissionSessionBean().FULLTEXT_DEFAULT)) {
                    for (int x = 0; x < ftFormats.size(); x++) {
                        fulltext = ftFormats.get(x);
                        if (fulltext.isFtDefault()) {
                            formats.add(fulltext.getName());
                            break;
                        }
                    }
                }
                // Get ALL full text versions from source
                if (this.getEasySubmissionSessionBean().getRadioSelectFulltext()
                        .equals(this.getEasySubmissionSessionBean().FULLTEXT_ALL)) {
                    for (int x = 0; x < ftFormats.size(); x++) {
                        fulltext = ftFormats.get(x);
                        formats.add(fulltext.getName());
                    }
                }
                String[] arrFormats = new String[formats.size()];
                byte[] ba = dataHandler.doFetch(
                        this.getEasySubmissionSessionBean().getCurrentExternalServiceType(), getServiceID(),
                        formats.toArray(arrFormats));
                LoginHelper loginHelper = (LoginHelper) this.getBean(LoginHelper.class);
                ByteArrayInputStream in = new ByteArrayInputStream(ba);
                URL fileURL = this.uploadFile(in, dataHandler.getContentType(),
                        loginHelper.getESciDocUserHandle());
                if (fileURL != null && !fileURL.toString().trim().equals("")) {
                    fileVO = dataHandler.getComponentVO();
                    MdsFileVO fileMd = fileVO.getDefaultMetadata();
                    fileVO.setStorage(FileVO.Storage.INTERNAL_MANAGED);
                    fileVO.setVisibility(dataHandler.getVisibility());
                    fileVO.setDefaultMetadata(fileMd);
                    fileVO.getDefaultMetadata().setTitle(new TextVO(
                            this.replaceSlashes(getServiceID().trim() + dataHandler.getFileEnding())));
                    fileVO.setMimeType(dataHandler.getContentType());
                    fileVO.setName(this.replaceSlashes(getServiceID().trim() + dataHandler.getFileEnding()));
                    FormatVO formatVO = new FormatVO();
                    formatVO.setType("dcterms:IMT");
                    formatVO.setValue(dataHandler.getContentType());
                    fileVO.getDefaultMetadata().getFormats().add(formatVO);
                    fileVO.setContent(fileURL.toString());
                    fileVO.getDefaultMetadata().setSize(ba.length);
                    fileVO.getDefaultMetadata().setDescription(
                            "File downloaded from " + service + " at " + CommonUtils.currentDate());
                    fileVO.setContentCategory(dataHandler.getContentCategory());
                    fileVOs.add(fileVO);
                }
            }
        } catch (AccessException inre) {
            logger.error("Error fetching from external import source", inre);
            error(getMessage("easy_submission_import_from_external_service_access_denied_error")
                    + getServiceID());
            return null;
        } catch (IdentifierNotRecognisedException inre) {
            logger.error("Error fetching from external import source", inre);
            error(getMessage("easy_submission_import_from_external_service_identifier_error") + getServiceID());
            return null;
        } catch (SourceNotAvailableException anae) {
            logger.error("Import source currently not available", anae);
            long millis = anae.getRetryAfter().getTime() - (new Date()).getTime();
            if (millis < 1) {
                millis = 1;
            }
            error(getMessage("easy_submission_external_source_not_available_error").replace("$1",
                    Math.ceil(millis / 1000) + ""));
            return null;
        } catch (FormatNotAvailableException e) {
            error(getMessage("formatNotAvailable_FromFetchingSource").replace("$1", e.getMessage())
                    .replace("$2", service));
            this.getEasySubmissionSessionBean()
                    .setRadioSelectFulltext(this.getEasySubmissionSessionBean().FULLTEXT_NONE);
        } catch (Exception e) {
            logger.error("Error fetching from external import source", e);
            error(getMessage("easy_submission_import_from_external_service_error"));
            return null;
        }
        // Generate item ValueObject
        if (fetchedItem != null && !fetchedItem.trim().equals("")) {
            try {
                itemVO = this.xmlTransforming.transformToPubItem(fetchedItem);
                // Upload fulltexts from other escidoc repositories to current repository
                if (this.getEasySubmissionSessionBean().isFulltext()
                        && this.getEasySubmissionSessionBean().getRadioSelectFulltext() != null
                        && this.getEasySubmissionSessionBean().getRadioSelectFulltext()
                                .equals(this.getEasySubmissionSessionBean().FULLTEXT_ALL)
                        && service.equalsIgnoreCase("escidoc")) {
                    boolean hasFile = false;
                    List<FileVO> fetchedFileList = itemVO.getFiles();
                    for (int i = 0; i < fetchedFileList.size(); i++) {
                        FileVO file = fetchedFileList.get(i);
                        if (file.getStorage().equals(FileVO.Storage.INTERNAL_MANAGED)) {
                            try {
                                FileVO newFile = new FileVO();
                                byte[] content = dataHandler.retrieveComponentContent(this.getServiceID(),
                                        file.getContent());
                                LoginHelper loginHelper = (LoginHelper) this.getBean(LoginHelper.class);
                                ByteArrayInputStream in = new ByteArrayInputStream(content);
                                URL fileURL;
                                fileURL = this.uploadFile(in, dataHandler.getContentType(),
                                        loginHelper.getESciDocUserHandle());
                                if (fileURL != null && !fileURL.toString().trim().equals("")
                                        && file.getVisibility().equals(FileVO.Visibility.PUBLIC)) {
                                    hasFile = true;
                                    newFile.setStorage(FileVO.Storage.INTERNAL_MANAGED);
                                    newFile.setVisibility(file.getVisibility());
                                    newFile.setDefaultMetadata(new MdsFileVO());
                                    newFile.getDefaultMetadata().setTitle(new TextVO(this
                                            .replaceSlashes(file.getDefaultMetadata().getTitle().getValue())));
                                    newFile.setMimeType(file.getMimeType());
                                    newFile.setName(this.replaceSlashes(file.getName()));
                                    FormatVO formatVO = new FormatVO();
                                    formatVO.setType("dcterms:IMT");
                                    formatVO.setValue(file.getMimeType());
                                    newFile.getDefaultMetadata().getFormats().add(formatVO);
                                    newFile.setContent(fileURL.toString());
                                    newFile.getDefaultMetadata().setSize(content.length);
                                    if (file.getDescription() != null) {
                                        newFile.getDefaultMetadata()
                                                .setDescription(file.getDescription() + " File downloaded from "
                                                        + service + " at " + CommonUtils.currentDate());
                                    } else {
                                        newFile.getDefaultMetadata().setDescription("File downloaded from "
                                                + service + " at " + CommonUtils.currentDate());
                                    }
                                    newFile.setContentCategory(file.getContentCategory());
                                    fileVOs.add(newFile);
                                }
                            } catch (Exception e) {
                                logger.error("Error fetching file from coreservice", e);
                            }
                        } else if (file.getStorage().equals(FileVO.Storage.EXTERNAL_URL)
                                && file.getVisibility().equals(FileVO.Visibility.PUBLIC)) {
                            // Locator is just added as is
                            fileVOs.add(file);
                        }
                    }
                    if (!hasFile) {
                        info(getMessage("easy_submission_import_from_external_service_identifier_info"));
                    }
                }
                itemVO.getFiles().clear();
                itemVO.setContext(getItem().getContext());
                if (dataHandler.getItemUrl() != null) {
                    IdentifierVO id = new IdentifierVO();
                    id.setType(IdType.URI);
                    try {
                        id.setId(java.net.URLDecoder.decode(dataHandler.getItemUrl().toString(), "UTF-8"));
                        itemVO.getMetadata().getIdentifiers().add(id);
                    } catch (UnsupportedEncodingException e) {
                        logger.warn("Item URL could not be decoded");
                    }
                }
                if (this.getEasySubmissionSessionBean().isFulltext() && !this.getEasySubmissionSessionBean()
                        .getRadioSelectFulltext().equals(this.getEasySubmissionSessionBean().FULLTEXT_NONE)) {
                    for (int i = 0; i < fileVOs.size(); i++) {
                        FileVO tmp = fileVOs.get(i);
                        itemVO.getFiles().add(tmp);
                    }
                    fileVOs.clear();
                }
                this.getItemControllerSessionBean().getCurrentPubItem().setMetadata(itemVO.getMetadata());
                this.getItemControllerSessionBean().getCurrentPubItem().getFiles().clear();
                this.getItemControllerSessionBean().getCurrentPubItem().getFiles().addAll(itemVO.getFiles());
                // Reset info for next call
                // this.setImportSourcesInfo(); Commented out because of browser back button problem.
                this.setBibTexInfo();
            } catch (TechnicalException e) {
                logger.warn("Error transforming item to pubItem.");
                error(getMessage("easy_submission_import_from_external_service_error"));
                return null;
            }
        } else {
            logger.warn("Empty fetched Item.");
            error(getMessage("easy_submission_import_from_external_service_error"));
            return null;
        }
    }
    // Fetch data from provided file
    else if (EasySubmissionSessionBean.IMPORT_METHOD_BIBTEX
            .equals(this.getEasySubmissionSessionBean().getImportMethod())) {
        String uploadResult = uploadBibtexFile();
        if (uploadResult == null) {
            return null;
        }
    }
    this.getEditItemSessionBean().clean();
    return "loadEditItem";
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.UploadTable.java

/**
 * @param row//from www. ja v a2s. co m
 * @param uploadData
 * @param invalidValues
 * 
 * Validates user-entered fields for the row.
 * Validation issues are added to invalidValues vector.
 */
public void validateRowValues(int row, UploadData uploadData, Vector<UploadTableInvalidValue> invalidValues) {

    if (uploadData.isEmptyRow(row)) {
        if (attachmentsPresent(uploadData, row)) {
            invalidValues.add(new UploadTableInvalidValue(null, this, this.uploadFields.get(0), row,
                    new Exception(String.format(getResourceString("UploadTable.AttachmentPresentButNoData"),
                            getTable().getTableInfo().getTitle()))));
        }
        return;
    }

    try {
        validatingValues = true;

        int seq = 0;
        boolean gotABlank = false;

        // for Locality table only
        LatLonConverter.FORMAT llFmt1 = null;
        LatLonConverter.FORMAT llFmt2 = null;
        // GeoRefConverter gc = new GeoRefConverter();
        UploadField llFld = null; // for 'generic' latlon errors.

        Vector<UploadTableInvalidValue> invalidNulls = new Vector<UploadTableInvalidValue>();
        Vector<Integer> blankSeqsLocal = new Vector<Integer>();
        for (Vector<UploadField> flds : uploadFields) {
            boolean isBlank = true;
            UploadField currFirstFld = null;
            for (UploadField fld : flds) {
                if (fld.getIndex() != -1) {
                    if (currFirstFld == null) {
                        currFirstFld = fld;
                    }
                    fld.setValue(uploadData.get(row, fld.getIndex()));
                    isBlank &= isBlankVal(fld, seq, row, uploadData);
                    ;
                    try {
                        if (invalidNull(fld, uploadData, row, seq)) {
                            if (shouldEnforceNonNullConstraint(row, uploadData, seq)) {
                                //throw new Exception(
                                //      getResourceString("WB_UPLOAD_FIELD_MUST_CONTAIN_DATA"));
                                invalidNulls.add(new UploadTableInvalidValue(
                                        getResourceString("WB_UPLOAD_FIELD_MUST_CONTAIN_DATA"), this, fld, row,
                                        null));
                                continue;
                            }
                        }
                        if (fld.getValue() != null && !"".equals(fld.getValue())
                                && fld.isAutoAssignForUpload()/* && fld == autoAssignedField*/) {
                            throw new Exception(
                                    UIRegistry.getResourceString("WB_UPLOAD_AutoAssMustBeBlankErrMsg"));
                        }
                        if (!pickListCheck(fld)) {
                            if (!fld.isReadOnlyValidValues()) {
                                if (uploader != Uploader.currentUpload) {
                                    invalidValues.add(new UploadTableInvalidValue(null, this, fld, null, row,
                                            new Exception(getInvalidPicklistValErrMsg(fld)), true));
                                    continue;
                                }
                            } else {
                                throw new Exception(getInvalidPicklistValErrMsg(fld));
                            }
                        }
                        Object[] finalVal = getArgForSetter(fld);
                        if (!updateMatches) {
                            //XXX But what if catnum has been changed... Shouldn't CatNum be made unchangeable???
                            checkUniqueness(finalVal, fld);
                        }
                    } catch (Exception e) {
                        invalidValues.add(new UploadTableInvalidValue(null, this, fld, row, e));
                    }
                }
                if (tblClass.equals(Locality.class)) {
                    // Check row to see that lat/long formats are the same.
                    String fldName = fld.getField().getName();
                    if (fldName.equalsIgnoreCase("latitude1") || fldName.equalsIgnoreCase("latitude2")
                            || fldName.equalsIgnoreCase("longitude1")
                            || fldName.equalsIgnoreCase("longitude2")) {
                        llFld = fld;
                        LatLonConverter.FORMAT fmt = geoRefConverter
                                .getLatLonFormat(StringUtils.stripToNull(fld.getValue()));
                        LatLonConverter.FORMAT llFmt = fldName.endsWith("1") ? llFmt1 : llFmt2;
                        boolean checkDecimalPlaces = true;
                        if (llFmt == null) {
                            llFmt = fmt;
                            if (fldName.endsWith("1")) {
                                llFmt1 = fmt;
                            } else {
                                llFmt2 = fmt;
                            }
                        } else {
                            if (!llFmt.equals(fmt)) {
                                checkDecimalPlaces = false;
                                invalidValues.add(new UploadTableInvalidValue(null, this, getLatLongFlds(), row,
                                        new Exception(
                                                UIRegistry.getResourceString("WB_UPLOADER_INVALID_LATLONG"))));
                            }
                        }
                        if (checkDecimalPlaces && fmt != null && fmt != LatLonConverter.FORMAT.None) {
                            //check decimal places
                            //lame
                            int c = fld.getValue().indexOf(decSep);
                            if (c > -1) {
                                int d;
                                String points = fld.getValue().substring(c + 1);
                                for (d = 0; d < points.length(); d++) {
                                    //System.out.println(points.substring(d, d+1));
                                    if (!"0123456789".contains(points.substring(d, d + 1)))
                                        break;
                                }
                                if (d > LatLonConverter.DECIMAL_SIZES[fmt.ordinal()]) {
                                    invalidValues.add(new UploadTableInvalidValue(null, this, fld, row,
                                            new Exception(String.format(
                                                    UIRegistry.getResourceString(
                                                            "WB_UPLOADER_TOO_MANY_FRACTION_DIGITS"),
                                                    LatLonConverter.DECIMAL_SIZES[fmt.ordinal()]))));
                                }
                            }
                        }
                    }
                    //Check LatLongType
                    if (fldName.equalsIgnoreCase("LatLongType")) {
                        boolean hasLat1 = false, hasLong1 = false, hasLat2 = false, hasLong2 = false;
                        for (UploadField f : getLatLongFlds()) {
                            f.setValue(uploadData.get(row, f.getIndex()));
                            String coordName = f.getField().getName();
                            if (coordName.equalsIgnoreCase("latitude1")
                                    && StringUtils.isNotBlank(f.getValue())) {
                                hasLat1 = true;
                            } else if (coordName.equalsIgnoreCase("longitude1")
                                    && StringUtils.isNotBlank(f.getValue())) {
                                hasLong1 = true;
                            } else if (coordName.equalsIgnoreCase("latitude2")
                                    && StringUtils.isNotBlank(f.getValue())) {
                                hasLat2 = true;
                            } else if (coordName.equalsIgnoreCase("longitude2")
                                    && StringUtils.isNotBlank(f.getValue())) {
                                hasLong2 = true;
                            }
                        }
                        boolean hasCoord1 = hasLat1 && hasLong1;
                        boolean hasCoord2 = hasLat2 && hasLong2;

                        if ((hasCoord1 || hasCoord2) && StringUtils.isBlank(fld.getValue())) {
                            invalidNulls.add(new UploadTableInvalidValue(
                                    getResourceString("WB_UPLOAD_FIELD_MUST_CONTAIN_DATA"), this, fld, row,
                                    null));
                            continue;

                        }

                        if (!hasCoord1 && !hasCoord2 && StringUtils.isBlank(fld.getValue())) {
                            continue;
                        }

                        //Assuming the pick list is localized...
                        String pntStr = UIRegistry.getResourceString("Locality.LL_TYPE_POINT");
                        String lineStr = UIRegistry.getResourceString("Locality.LL_TYPE_LINE");
                        String rectStr = UIRegistry.getResourceString("Locality.LL_TYPE_RECTANGLE");

                        Set<String> validValues = new TreeSet<String>();
                        for (String item : fld.getValidValues().keySet()) {
                            if (item.equals(pntStr) && hasCoord1 && !hasCoord2) {
                                validValues.add(item);
                            } else if ((item.equals(lineStr) || item.equals(rectStr)) && hasCoord1
                                    && hasCoord2) {
                                validValues.add(item);
                            }
                        }
                        if (!validValues.contains(fld.getValue())) {
                            if (uploader != Uploader.currentUpload) {
                                invalidValues.add(new UploadTableInvalidValue(null, this, fld, null, row,
                                        new Exception(getInvalidPicklistValErrMsg(fld, validValues)), false));
                                continue;
                            }
                        }
                    }
                }
            }

            if (tblClass.equals(Locality.class)) {
                if (llFmt1 != llFmt2 && llFmt2 != null && llFmt2 != LatLonConverter.FORMAT.None) {
                    invalidValues.add(new UploadTableInvalidValue(null, this, llFld, row,
                            new Exception(UIRegistry.getResourceString("WB_UPLOADER_INVALID_LATLONG"))));
                }
            }

            if (isBlank) {
                if (attachmentsPresent(uploadData, row)) {
                    invalidValues
                            .add(new UploadTableInvalidValue(null, this, flds, row,
                                    new Exception(String.format(
                                            getResourceString("UploadTable.AttachmentPresentButNoData"),
                                            getTable().getTableInfo().getTitle()))));
                }

            }
            isBlank = isBlankSequence(isBlank, uploadData, row, seq, null);
            blankSeqs.set(seq, isBlank);
            if (isBlank)
            /*
             * Disallow situations where 1-many lists have 'holes' - eg.
             * CollectorLastName2 is blank but CollectorLastName1 and -3 are
             * not.
             */
            {
                gotABlank = true;
                blankSeqsLocal.add(seq);

            } else if (!isBlank && gotABlank && plugHoles) {
                for (Integer blank : blankSeqsLocal) {
                    for (UploadField blankSeqFld : getBlankFields(blank, row, uploadData)) {
                        addInvalidValueMsgForOneToManySkip(invalidValues, blankSeqFld, toString(), row, blank);
                    }
                }
                blankSeqsLocal.clear();
            }

            invalidValues.addAll(invalidNulls);
            invalidNulls.clear();

            seq++;
        }
        if (tblClass.equals(Determination.class)) {
            // check that isCurrent is ok. 1 and only one true.
            boolean isCurrentPresent = false;
            UploadField anIsCurrentFld = null;
            boolean isBlank = true;
            // for (int row = 0; row < uploadData.getRows(); row++)
            // {
            int trueCount = 0;
            for (Vector<UploadField> flds : uploadFields) {
                for (UploadField fld : flds) {
                    if (isBlank && StringUtils.isNotBlank(uploadData.get(row, fld.getIndex()))) {
                        isBlank = false;
                    }
                    if (fld.getField().getName().equalsIgnoreCase("iscurrent")) {
                        isCurrentPresent = true;
                        if (anIsCurrentFld == null) {
                            anIsCurrentFld = fld;
                        }
                        fld.setValue(uploadData.get(row, fld.getIndex()));
                        try {
                            Object[] boolVal = getArgForSetter(fld);
                            if (boolVal[0] != null && (Boolean) boolVal[0]) {
                                trueCount++;
                            }
                        } catch (Exception e) {
                            // ignore. assuming problem was already caught
                            // above.
                        }
                    }
                }
            }
            if (isCurrentPresent && !isBlank && trueCount != 1) {
                invalidValues.add(new UploadTableInvalidValue(null, this, anIsCurrentFld, row,
                        new Exception(getResourceString("WB_UPLOAD_ONE_CURRENT_DETERMINATION"))));
            }
            // }
        }

        if (tblClass.equals(Agent.class)) {
            // check that isCurrent is ok. 1 and only one true.
            boolean nonPersonNonEmpty = false;
            boolean isNonPerson = false;
            Vector<UploadField> personOnlyFlds = new Vector<UploadField>();
            for (Vector<UploadField> flds : uploadFields) {
                for (UploadField fld : flds) {
                    try {
                        if (fld.getField().getName().equalsIgnoreCase("firstName")
                                || fld.getField().getName().equalsIgnoreCase("middleInitial")
                                || fld.getField().getName().equalsIgnoreCase("title")) {
                            Object[] val = getArgForSetter(fld);
                            nonPersonNonEmpty = StringUtils.isNotEmpty((String) val[0]);
                            personOnlyFlds.add(fld);
                        }
                        if (fld.getField().getName().equalsIgnoreCase("agenttype")) {
                            Object[] val = getArgForSetter(fld);
                            isNonPerson = val[0] != null && !((Byte) val[0]).equals(Agent.PERSON);
                            if (!isNonPerson) {
                                break;
                            }
                        }
                    } catch (Exception e) {
                        // ignore. assuming problem was already caught
                        // above.
                    }
                }
                if (isNonPerson && nonPersonNonEmpty) {
                    for (UploadField poFld : personOnlyFlds) {
                        invalidValues.add(new UploadTableInvalidValue(null, this, poFld, row, new Exception(
                                getResourceString("UploadTable.FieldNotApplicableForAgentType"))));
                    }
                }
            }
        }
    } finally {
        validatingValues = false;
    }

}