Example usage for java.util Date toString

List of usage examples for java.util Date toString

Introduction

In this page you can find the example usage for java.util Date toString.

Prototype

public String toString() 

Source Link

Document

Converts this Date object to a String of the form:
 dow mon dd hh:mm:ss zzz yyyy
where:
  • dow is the day of the week ( Sun, Mon, Tue, Wed, Thu, Fri, Sat ).

    Usage

    From source file:gov.utah.dts.sdc.actions.ThirdPartyStudentAction.java

    public String update_change() throws Exception {
        log.debug("update_change");
        int dbCode = 0;
        int webCode = 0;
    
        int start = decodeTime(getRoadTestStartTime());
        Date startDate = new Date(getRoadTestCompletionDate().getTime() + start);
        log.debug("startDate " + startDate.toString());
    
        int end = decodeTime(getRoadTestEndTime());
        Date endDate = new Date(getRoadTestCompletionDate().getTime() + end);
        log.debug("endDate " + endDate.toString());
    
        if (endDate.before(startDate)) {
            addActionError("Start Time Must Be Before End Time");
            //set variables for jsp
            getCurrentStudent().setFileNumber(getFileNumber());
            getCurrentStudent().setFirstName(getFirstName());
            getCurrentStudent().setMiddleName(getMiddleName());
            getCurrentStudent().setLastName(getLastName());
            getCurrentStudent().setDob(getDob());
            getCurrentStudent().setStudentPk(getStudentPk());
            getCurrentStudent().setLicenseType(getLicenseType());
            return INPUT;
        }//from  w  w  w. ja  va2  s.  c o m
    
        if (getRoadTestScore().intValue() <= 20) {
            //add completion_data and send Completion update student record.
            webCode = webSend();
            if (webCode > 0) {
                //update Student
                Map<String, Object> hm = new HashMap<String, Object>();
                hm.put("studentPk", getStudentPk());
                hm.put("roadTestCompletionDate", getRoadTestCompletionDate());
                hm.put("roadTestScore", getRoadTestScore());
                hm.put("roadTestInstructorFk", getRoadInstructorPk());
                hm.put("roadTestCompletionSchoolNumber", getSchoolNumber(getSchoolFk()));
                hm.put("schoolFk", getSchoolFk());
                dbCode = getStudentService().update(hm);
    
                //update audit completion data
                updateRoadAuditDate(getRoadMap(startDate, endDate));
            }
            log.debug("Passed road test");
        } else {
            //just update completion data.
            log.debug("Failed road test inserting audit info only");
            updateRoadAuditDate(getRoadMap(startDate, endDate));
        }
    
        if (dbCode > 0) {
            addActionMessage("SDC saved student record.");
        }
        log.debug("update webResponse " + webCode + " dbResponse " + dbCode);
    
        return SUCCESS;
    }
    

    From source file:org.mendix.dslcommon.openarchitectureware.Mod4jWorkflowRunner.java

    /**
     * General Mod4j workflow runner. // ww  w .j  av  a 2 s. c  o m
     * 
     * @param wfFile
     *            absolute path string of the workflow file to execute
     * @param properties
     *            Map containing the properties for <code>wfFile</code>.
     * @throws Mod4jWorkflowException
     */
    public void runWorkflow(final String wfFile, final Map<String, String> properties)
            throws Mod4jWorkflowException {
    
        Map<String, Object> slotContents = new HashMap<String, Object>();
        WorkflowRunner runner = new WorkflowRunner();
    
        String propertiesListing = "";
        for (Map.Entry<String, String> prop : properties.entrySet()) {
            propertiesListing += "\t\t" + prop.toString() + "\n";
        }
    
        logger.info("Running workflow [" + wfFile + "] with properties : \n" + propertiesListing);
    
        Date date = new Date(System.currentTimeMillis());
        //        System.err.println("03 ================== " + date.toString() + ": workflow [" + wfFile + "]");
        //        ResourceLoader loader = ResourceLoaderFactory.getCurrentThreadResourceLoader();
        //        
        //        System.err.println("Classloader: " + (loader == null ? "NULL" : loader.toString() ) ) ;
        //        if( loader == null ){
        //              CachingResourceLoaderImpl crl = new CachingResourceLoaderImpl(
        //                      new OsgiResourceLoader("org.mendix.common", FileTrack.class.getClassLoader() )
        //              ); 
        //    
        //              ResourceLoaderFactory.setCurrentThreadResourceLoader(crl);
        //        }
        //
        //        date = new Date(System.currentTimeMillis());
        System.err.println("04 ================== " + date.toString() + ": workflow [" + wfFile + "]");
        if (!runner.run(wfFile, new NullProgressMonitor(), properties, slotContents)) {
            logger.error("--------------------------------------------------------------------------------------");
            logger.error("------- ERROR(S) detected while running workflow : [" + wfFile + "] ");
            logger.error("------- See logging above for more details.");
            logger.error("--------------------------------------------------------------------------------------");
            throw new Mod4jWorkflowException("ERROR(S) detected while running workflow :" + wfFile);
        }
        date = new Date(System.currentTimeMillis());
        System.err.println("05 ================== " + date.toString() + ": workflow [" + wfFile + "]");
        logger.info("--------------------------------------------------------------------------");
        logger.info("-------- Workflow SUCCESSFUL! ");
        logger.info("--------------------------------------------------------------------------");
    }
    

    From source file:gov.utah.dts.sdc.actions.ThirdPartyStudentAction.java

    public String update() throws Exception {
        log.debug("update");
    
        //getCurrentStudent().setSchoolFk(getSchoolFk());   // remedy ticket 360423
    
        int dbCode = 0;
        int webCode = 0;
    
        int start = decodeTime(getRoadTestStartTime());
        Date startDate = new Date(getRoadTestCompletionDate().getTime() + start);
        log.debug("startDate " + startDate.toString());
    
        int end = decodeTime(getRoadTestEndTime());
        Date endDate = new Date(getRoadTestCompletionDate().getTime() + end);
        log.debug("endDate " + endDate.toString());
    
        if (endDate.before(startDate)) {
            addActionError("Start Time Must Be Before End Time");
            //set variables for jsp
            getCurrentStudent().setFileNumber(getFileNumber());
            getCurrentStudent().setFirstName(getFirstName());
            getCurrentStudent().setMiddleName(getMiddleName());
            getCurrentStudent().setLastName(getLastName());
            getCurrentStudent().setDob(getDob());
            getCurrentStudent().setStudentPk(getStudentPk());
            getCurrentStudent().setLicenseType(getLicenseType());
            return INPUT;
        }/*from  w  w w .  j a  va  2 s .c  o m*/
    
        if (getRoadTestScore().intValue() <= 20) {
            //add completion_data and send Completion update student record.
            webCode = webSend();
            if (webCode > 0) {
                //update Student
                Map<String, Object> hm = new HashMap<String, Object>();
                hm.put("studentPk", getStudentPk());
                hm.put("roadTestCompletionDate", getRoadTestCompletionDate());
                hm.put("roadTestScore", getRoadTestScore());
                hm.put("roadTestInstructorFk", getRoadInstructorPk());
                hm.put("roadTestCompletionSchoolNumber", getSchoolNumber(getSchoolFk()));
                hm.put("schoolFk", getSchoolFk());
                dbCode = getStudentService().update(hm);
                //insert audit completion data
                insertRoadAuditDate(getRoadMap(startDate, endDate));
            }
            log.debug("Passed road test");
        } else {
            //just insert completion data.
            log.debug("Failed road test inserting audit info only");
            insertRoadAuditDate(getRoadMap(startDate, endDate));
        }
    
        if (dbCode > 0) {
            addActionMessage("SDC saved student record.");
        }
        log.debug("update webResponse " + webCode + " dbResponse " + dbCode);
    
        return SUCCESS;
    }
    

    From source file:org.apache.ranger.rest.TestAssetREST.java

    @Test
    public void testGetResourceJSON() {
        RangerService rangerService = rangerService(Id);
        String file = "testGetResourceJSON";
        VXAsset vXAsset = vXAsset(Id);//from  w w w  .j  a  v a  2s .  co  m
        Date date = new Date();
        String strdt = date.toString();
        X509Certificate[] certchain = new X509Certificate[1];
        certchain[0] = Mockito.mock(X509Certificate.class);
        ServicePolicies servicePolicies = servicePolicies();
        RangerPolicy rangerPolicy = rangerPolicy(Id);
        List<RangerPolicy> policies = new ArrayList<RangerPolicy>();
        policies.add(rangerPolicy);
        Mockito.when(request.getParameter("epoch")).thenReturn(strdt);
        Mockito.when(request.getAttribute("javax.servlet.request.X509Certificate")).thenReturn(certchain);
        Mockito.when(request.getHeader("X-FORWARDED-FOR")).thenReturn("valid");
        Mockito.when(request.isSecure()).thenReturn(true);
        Mockito.when(request.getParameter("policyCount")).thenReturn("4");
        Mockito.when(request.getParameter("agentId")).thenReturn("12");
        // Mockito.when(PropertiesUtil.getBooleanProperty("ranger.service.http.enabled",true)).thenReturn(true);
        try {
            Mockito.when(serviceREST.getServicePoliciesIfUpdated(Mockito.anyString(), Mockito.anyLong(),
                    Mockito.anyLong(), Mockito.anyString(), Mockito.anyString(),
                    (HttpServletRequest) Mockito.any())).thenReturn(servicePolicies);
        } catch (Exception e) {
            fail("test failed due to: " + e.getMessage());
        }
        Mockito.when(serviceUtil.getServiceByName("hdfs_dev")).thenReturn(rangerService);
        Mockito.when(serviceUtil.toVXAsset(rangerService)).thenReturn(vXAsset);
        Mockito.when(assetMgr.getLatestRepoPolicy((VXAsset) Mockito.any(), Mockito.<VXResource>anyList(),
                Mockito.anyLong(), (X509Certificate[]) Mockito.any(), Mockito.anyBoolean(), Mockito.anyString(),
                Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString()))
                .thenReturn(file);
        String actualFile = assetREST.getResourceJSON(request, "hdfs_dev");
        Assert.assertEquals(file, actualFile);
        Mockito.verify(serviceUtil).getServiceByName("hdfs_dev");
        Mockito.verify(serviceUtil).toVXAsset(rangerService);
        Mockito.verify(request).getParameter("epoch");
        Mockito.verify(request).getAttribute("javax.servlet.request.X509Certificate");
        Mockito.verify(request).getHeader("X-FORWARDED-FOR");
        Mockito.verify(request).isSecure();
        Mockito.verify(request).getParameter("policyCount");
        Mockito.verify(request).getParameter("agentId");
        Mockito.verify(assetMgr).getLatestRepoPolicy((VXAsset) Mockito.any(), Mockito.<VXResource>anyList(),
                Mockito.anyLong(), (X509Certificate[]) Mockito.any(), Mockito.anyBoolean(), Mockito.anyString(),
                Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString());
    }
    

    From source file:com.pearson.eidetic.driver.threads.subthreads.SnapshotVolumeSync.java

    public boolean snapshotCreation(AmazonEC2Client ec2Client, Volume vol, Date date) {
        if ((date == null) || (ec2Client == null) || (vol == null)) {
            return false;
        }/*from   w ww.j  av a2  s.  c o m*/
    
        try {
    
            Collection<Tag> tags_volume = getResourceTags(vol);
    
            String volumeAttachmentInstance = "none";
            try {
                volumeAttachmentInstance = vol.getAttachments().get(0).getInstanceId();
            } catch (Exception e) {
                logger.debug("Volume not attached to instance: " + vol.getVolumeId());
            }
    
            String description;
            if (Validator_) {
                description = "sync_snapshot " + vol.getVolumeId() + " called by Eidetic Validator Synchronizer at "
                        + date.toString() + ". Volume attached to " + volumeAttachmentInstance;
            } else {
                description = "sync_snapshot " + vol.getVolumeId() + " by Eidetic Synchronizer at "
                        + date.toString() + ". Volume attached to " + volumeAttachmentInstance;
            }
    
            Snapshot current_snap;
            try {
                current_snap = createSnapshotOfVolume(ec2Client, vol, description, numRetries_,
                        maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_);
            } catch (Exception e) {
                logger.error("awsAccountId=\"" + uniqueAwsAccountIdentifier_
                        + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId()
                        + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                        + StackTrace.getStringFromStackTrace(e) + "\"");
                return false;
            }
    
            try {
                setResourceTags(ec2Client, current_snap, tags_volume, numRetries_, maxApiRequestsPerSecond_,
                        uniqueAwsAccountIdentifier_);
            } catch (Exception e) {
                logger.error("awsAccountId=\"" + uniqueAwsAccountIdentifier_
                        + "\",Event\"Error\", Error=\"error adding tags to snapshot\", Snapshot_id=\""
                        + current_snap.getVolumeId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                        + StackTrace.getStringFromStackTrace(e) + "\"");
                return false;
            }
    
        } catch (Exception e) {
            logger.error("awsAccountId=\"" + uniqueAwsAccountIdentifier_
                    + "\",Event=\"Error, Error=\"error in snapshotCreation\", stacktrace=\"" + e.toString()
                    + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\"");
            return false;
        }
    
        return true;
    }
    

    From source file:gov.utah.dts.sdc.actions.StudentCreateAction.java

    public String sendStringDate(boolean set, Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String retVal = "";
    
        //false send date
        //true send blank
        if (date != null) {
            log.debug("sendDate " + date.toString());
            if (!set) {
                retVal = sdf.format(date);//from w w  w  .ja va  2s .  c  o m
            }
        }
        return retVal;
    }
    

    From source file:org.apache.usergrid.apm.service.SessionDBServiceImpl.java

    @SuppressWarnings("unchecked")
    @Override/*from w w w  . ja  v a  2  s .  c o  m*/
    public List<SummarySessionMetrics> getSummarySessionsForDevices(Long applicationId, List<String> deviceIds,
            Date sessionExpiryTime) throws HibernateException {
    
        log.info("getting summary session metrics with for " + deviceIds.toString() + " sessionExpiryTime "
                + sessionExpiryTime.toString());
        if (deviceIds == null || deviceIds.size() == 0 || sessionExpiryTime == null) {
            log.info(
                    "List of deviceIds is null or sessionExpiryTime is null. Going to return an empty summary session metrics");
            return null;
        }
    
        //      String queryString = "FROM SummarySessionMetrics m where m.appId = :appId and m.deviceId in (:devices) " +
        //      "and m.sessionEndTime >= :sessionExpTime "; 
    
        String queryString = "FROM SummarySessionMetrics m where m.appId = :appId and m.deviceId in (:devices) ";
    
        List<SummarySessionMetrics> metrics = null;
        Session session = null;
        Transaction transaction = null;
        try {
            session = ServiceFactory.getAnalyticsHibernateSession();
            transaction = session.beginTransaction();
            Query query = session.createQuery(queryString);
            query.setParameter("appId", applicationId);
            query.setParameterList("devices", deviceIds);
    
            //This doesn't make any sense - need to eliminate because session expiry time is different for each session
            //query.setParameter("sessionExpTime", sessionExpiryTime);
    
            /*Criteria crit = session.createCriteria(SummarySessionMetrics.class);
            session.createQuery(arg0)
            crit.add(Restrictions.eq("appId", applicationId));
            crit.add(Restrictions.in("deviceId", deviceIds));
            crit.add(Restrictions.le("sessionEndTime", sessionExpiryTime));  
            crit.setProjection(Projections.groupProperty("deviceId"));
            crit.setProjection(Projections.property("sessionStartTime"));
            crit.addOrder(Order.desc("sessionEndTime"));
                    
            log.info("getting summary session metrics with for " + deviceIds.toString() +  " sessionExpiryTime " + sessionExpiryTime.toString());
            metrics = (List<SummarySessionMetrics>) crit.list();*/
            metrics = query.list();
    
            transaction.commit();
        } catch (Exception e) {
            e.printStackTrace();
            transaction.rollback();
            throw new HibernateException("Cannot get metrics from Summary SessionMetrics ", e);
        }
        return metrics;
    }
    

    From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java

    public void testDefaultDateDeserializationUsingBuilder() throws Exception {
        Date now = new Date(1315806903103L);
        String json = oson.toJson(now);
        Date extracted = oson.fromJson(json, Date.class);
        //System.err.println(now.toString());
        //System.err.println(extracted.toString());
        assertEquals(now.toString(), extracted.toString());
    }
    

    From source file:com.sample.partnerprofile.portlet.JSPPortlet.java

    public void processAction(ActionRequest req, ActionResponse res) throws IOException, PortletException {
    
        String command = req.getParameter("command");
    
        int id = 0;/* w w  w  . j  a v  a2 s. c  o  m*/
        long userId = 0;
        userId = PortalUtil.getUserId(req);
        System.out.println("userId in action request este " + String.valueOf(userId));
    
        try {
            id = Integer.parseInt(req.getParameter("id"));
            //userId = Integer.parseInt(req.getParameter("userId"));
        } catch (Exception e) {
        }
    
        // user relatesd
        String name = req.getParameter("first_name");
        String userLastName = req.getParameter("last_name");
        String userCompanyName = req.getParameter("userCompanyName");
        String userPositionCompany = req.getParameter("userPositionCompany");
        String userMobilePhone = req.getParameter("telephone_user");
        String userWorkPhone = req.getParameter("telefax_user");
        // company related
        String partnerDescription = req.getParameter("partnerDescription");
        int partnerNumber = 1;
        if (req.getParameter("partnerNumber") != null)
            partnerNumber = Integer.parseInt(req.getParameter("partnerNumber"));
        String telephone = req.getParameter("telephone");
        String telefax = req.getParameter("telefax");
        String mail = req.getParameter("mail");
        String street1 = req.getParameter("street1");
        String street2 = req.getParameter("street2");
        String zipcode = req.getParameter("zipcode");
        String city = req.getParameter("city");
        String state_province = req.getParameter("state_province");
        String country = req.getParameter("country");
        String micrositeAdress = req.getParameter("micrositeAdress");
        String company_website = req.getParameter("company_website");
        String noemployees = req.getParameter("noemployees");
        String geographic_coverage = req.getParameter("geographic_coverage");
        String parent_company_name = req.getParameter("parent_company_name");
        String country_parent_company = req.getParameter("country_parent_company");
        String channel_partner_since = req.getParameter("channel_partner_since");
        String primary_business_type = req.getParameter("primary_business_type");
        String secondary_business_type = req.getParameter("secondary_business_type");
        String sap_solution_focus = req.getParameter("sap_solution_focus");
        String industry_micro_vertical_focus = req.getParameter("industry_micro_vertical_focus");
    
        String last_review_Date = req.getParameter("last_review_Date");
        String reviewed_by = req.getParameter("reviewed_by");
        String profile_added = "";//req.getParameter("profile_added");
        String date_updated = "";//req.getParameter("date_updated");
        String modified_by = req.getParameter("modified_by");
        String[] SAPitems = req.getParameterValues("sap_solution_focus");
        String[] industry = req.getParameterValues("industry");
        String[] countryCoverage = req.getParameterValues("country_coverage");
    
        //search related
        String[] SAPitems_search = req.getParameterValues("sap_solution_focus_search");
        String industrySearch = req.getParameter("industry_search");
        String[] countryCoverage_search = req.getParameterValues("country_coverage_search");
        String country_search = req.getParameter("country_search");
        String primary_business_type_search = req.getParameter("primary_business_type_search");
        try {
            SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
            DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
    
            if (command.equals("add")) {
                // user
                // user adress + phone
    
                // company
                CompanyItem companyItem = new CompanyItem();
    
                companyItem.setName(userCompanyName);
                companyItem.setDescription(partnerDescription);
                companyItem.setCompanyNo(partnerNumber);
                companyItem.setCompanyFriendlySite(micrositeAdress);
                companyItem.setCompanySite(company_website);
                if (noemployees != null && !noemployees.isEmpty())
                    companyItem.setCompanyEmpNo(Integer.parseInt(noemployees));
                companyItem.setParentCompanyName(parent_company_name);
                if (channel_partner_since != null && !channel_partner_since.isEmpty())
                    companyItem.setYear(Integer.parseInt(channel_partner_since));
                if (country_parent_company != "") {
                    CountryItem countryItemTemp = CountryItemDAO.getCountryItemByName(country_parent_company);
                    if (countryItemTemp != null)
                        companyItem.setCountryRegistrationId(countryItemTemp.getId());
                }
    
                Date tempDate = new Date();
    
                companyItem.setDateUpdated(new Date());
                companyItem.setDateLastReview(new Date());
                companyItem.setDateUpdated(new Date());
    
                if (last_review_Date != null && !last_review_Date.isEmpty()) {
                    try {
                        tempDate = format.parse(last_review_Date);
                        String value = tempDate.toString();
                        companyItem.setDateLastReview(tempDate);
                    } catch (ParseException ex) {
                    }
                }
    
                companyItem.setReviewedBy(reviewed_by);
                companyItem.setModifiedBy(modified_by);
                companyItem.setCompanyUserId(userId);
    
                CompanyItemDAO.addCompanyItem(companyItem);
    
                int adressId = companyItem.getAdressId();
                AdressItem adressItem = null;
                if (adressId <= 0) {
                    adressItem = new AdressItem();
                    adressItem.setCompanyId(companyItem.getId());
                    adressItem.setStreet1(street1);
                    adressItem.setStreet2(street2);
                    adressItem.setCity(city);
                    adressItem.setZip(zipcode);
                    adressItem.setStateregionname(state_province);
                    adressItem.setMail(mail);
                    // countryId
                    if (country != "") {
                        CountryItem countryItemTemp = CountryItemDAO.getCountryItemByName(country);
                        adressItem.setCountryId(countryItemTemp.getId());
                    }
                    AdressItemDAO.addAdressItem(adressItem);
    
                    companyItem.setAdressId(adressItem.getId());
    
                    if (telephone != "")
                        AdressItemDAO.updatePhoneItem(adressItem, telephone, 1);
                    if (telefax != "")
                        AdressItemDAO.updatePhoneItem(adressItem, telefax, 2);
                    AdressItemDAO.updateAdressItem(adressItem);
                }
                // Do update in main table
                CompanyItemDAO.updateCompanyItem(companyItem);
    
                //2 . SAP solution focus
                CompanyUtil.updateCompanySAPSolutionList(companyItem, SAPitems);
                // 3. Industry
                CompanyUtil.updateCompanyIndustriesList(companyItem, industry);
                //4. primary business type -- primary_business_type
                if (primary_business_type != null)
                    CompanyUtil.updateBusinessType(companyItem, primary_business_type, 1);
                //5. secondary business type - secondary_business_type
                if (secondary_business_type != null)
                    CompanyUtil.updateBusinessType(companyItem, secondary_business_type, 2);
                //6. country coverage
    
                if (countryCoverage != null) {
                    for (int loopIndex = 0; loopIndex < countryCoverage.length; loopIndex++) {
                        System.out.println(countryCoverage[loopIndex]);
                    }
                }
                CompanyUtil.updateCompanyCountryCoverage(companyItem, countryCoverage);
    
            } else if (command.equals("edit")) {
                //user
                CompanyItem companyItem = CompanyItemDAO.getCompanyItem(id);
    
                companyItem.setName(userCompanyName);
                companyItem.setDescription(partnerDescription);
                companyItem.setCompanyNo(partnerNumber);
                companyItem.setCompanyFriendlySite(micrositeAdress);
                companyItem.setCompanySite(company_website);
                if (noemployees != null && !noemployees.isEmpty())
                    companyItem.setCompanyEmpNo(Integer.parseInt(noemployees));
                companyItem.setParentCompanyName(parent_company_name);
                if (channel_partner_since != null && !channel_partner_since.isEmpty())
                    companyItem.setYear(Integer.parseInt(channel_partner_since));
                if (country_parent_company != "") {
                    CountryItem countryItemTemp = CountryItemDAO.getCountryItemByName(country_parent_company);
                    if (countryItemTemp != null)
                        companyItem.setCountryRegistrationId(countryItemTemp.getId());
                }
    
                Date date = new Date();
                try {
                    date = format.parse(last_review_Date);
                } catch (ParseException ex) {
                }
                companyItem.setDateLastReview(date);
                /*try {date = df.parse(profile_added);
                }catch (ParseException ex){
                }
                companyItem.setDateCreated(date);*/
                companyItem.setDateUpdated(new Date());
                companyItem.setReviewedBy(reviewed_by);
                companyItem.setModifiedBy(modified_by);
    
                // update childs
                //1 . adress + phone
                int adressId = companyItem.getAdressId();
                AdressItem adressItem = null;
                boolean bIsNew = false;
                if (adressId > 0) {
                    adressItem = AdressItemDAO.getAdressItem(adressId);
                } else {
                    adressItem = new AdressItem();
                    bIsNew = true;
                }
                if (adressItem != null) {
                    adressItem.setCompanyId(id);
                    adressItem.setStreet1(street1);
                    adressItem.setStreet2(street2);
                    adressItem.setCity(city);
                    adressItem.setZip(zipcode);
                    adressItem.setStateregionname(state_province);
                    adressItem.setMail(mail);
                    // countryId
                    if (country != "") {
                        CountryItem countryItemTemp = CountryItemDAO.getCountryItemByName(country);
                        adressItem.setCountryId(countryItemTemp.getId());
                    }
    
                    if (bIsNew) {
                        AdressItemDAO.addAdressItem(adressItem);
                        companyItem.setAdressId(adressItem.getId());
                    }
                    if (telephone != "")
                        AdressItemDAO.updatePhoneItem(adressItem, telephone, 1);
                    if (telefax != "")
                        AdressItemDAO.updatePhoneItem(adressItem, telefax, 2);
                    AdressItemDAO.updateAdressItem(adressItem);
                }
                // Do update in main table
                CompanyItemDAO.updateCompanyItem(companyItem);
    
                //2 . SAP solution focus
                CompanyUtil.updateCompanySAPSolutionList(companyItem, SAPitems);
                // 3. Industry
                CompanyUtil.updateCompanyIndustriesList(companyItem, industry);
                //4. primary business type -- primary_business_type
                if (primary_business_type != null)
                    CompanyUtil.updateBusinessType(companyItem, primary_business_type, 1);
                //5. secondary business type - secondary_business_type
                if (secondary_business_type != null)
                    CompanyUtil.updateBusinessType(companyItem, secondary_business_type, 2);
                //6. country coverage
                CompanyUtil.updateCompanyCountryCoverage(companyItem, countryCoverage);
            } else if (command.equals("delete")) {
                CompanyItemDAO.deleteCompanyItem(id);
            } else if (command.equals("search")) {
                ;
            } else if (command.equals("viewall")) {
                ;
            }
        } catch (SQLException sqle) {
            throw new PortletException(sqle);
        }
    
    }
    

    From source file:com.sample.searchprofile.portlet.JSPPortlet.java

    public void processAction(ActionRequest req, ActionResponse res) throws IOException, PortletException {
    
        String command = req.getParameter("command");
    
        int id = 0;/*ww  w.  ja v a  2  s.  co  m*/
        int userId = 0;
    
        try {
            id = Integer.parseInt(req.getParameter("id"));
            //userId = Integer.parseInt(req.getParameter("userId"));
        } catch (Exception e) {
        }
    
        // user relatesd
        String name = req.getParameter("first_name");
        String userLastName = req.getParameter("last_name");
        String userCompanyName = req.getParameter("userCompanyName");
        String userPositionCompany = req.getParameter("userPositionCompany");
        String userMobilePhone = req.getParameter("telephone_user");
        String userWorkPhone = req.getParameter("telefax_user");
        // company related
        String partnerDescription = req.getParameter("partnerDescription");
        int partnerNumber = 1;
        if (req.getParameter("partnerNumber") != null)
            partnerNumber = Integer.parseInt(req.getParameter("partnerNumber"));
        String telephone = req.getParameter("telephone");
        String telefax = req.getParameter("telefax");
        String mail = req.getParameter("mail");
        String street1 = req.getParameter("street1");
        String street2 = req.getParameter("street2");
        String zipcode = req.getParameter("zipcode");
        String city = req.getParameter("city");
        String state_province = req.getParameter("state_province");
        String country = req.getParameter("country");
        String micrositeAdress = req.getParameter("micrositeAdress");
        String company_website = req.getParameter("company_website");
        String noemployees = req.getParameter("noemployees");
        String geographic_coverage = req.getParameter("geographic_coverage");
        String parent_company_name = req.getParameter("parent_company_name");
        String country_parent_company = req.getParameter("country_parent_company");
        String channel_partner_since = req.getParameter("channel_partner_since");
        String primary_business_type = req.getParameter("primary_business_type");
        String secondary_business_type = req.getParameter("secondary_business_type");
        String sap_solution_focus = req.getParameter("sap_solution_focus");
        String industry_micro_vertical_focus = req.getParameter("industry_micro_vertical_focus");
    
        String last_review_Date = req.getParameter("last_review_Date");
        String reviewed_by = req.getParameter("reviewed_by");
        String profile_added = "";//req.getParameter("profile_added");
        String date_updated = "";//req.getParameter("date_updated");
        String modified_by = req.getParameter("modified_by");
        String[] SAPitems = req.getParameterValues("sap_solution_focus");
        String[] industry = req.getParameterValues("industry");
        String[] countryCoverage = req.getParameterValues("country_coverage");
    
        //search related
        String[] SAPitems_search = req.getParameterValues("sap_solution_focus_search");
        String industrySearch = req.getParameter("industry_search");
        String[] countryCoverage_search = req.getParameterValues("country_coverage_search");
        String country_search = req.getParameter("country_search");
        String primary_business_type_search = req.getParameter("primary_business_type_search");
        if (command == null)
            return;
        try {
            DateFormat df = DateFormat.getDateInstance();
    
            if (command.equals("add")) {
                // user
                // user adress + phone
    
                // company
                CompanyItem companyItem = new CompanyItem();
    
                companyItem.setName(userCompanyName);
                companyItem.setDescription(partnerDescription);
                companyItem.setCompanyNo(partnerNumber);
                companyItem.setCompanyFriendlySite(micrositeAdress);
                companyItem.setCompanySite(company_website);
                if (noemployees != null && !noemployees.isEmpty())
                    companyItem.setCompanyEmpNo(Integer.parseInt(noemployees));
                companyItem.setParentCompanyName(parent_company_name);
                if (channel_partner_since != null && !channel_partner_since.isEmpty())
                    companyItem.setYear(Integer.parseInt(channel_partner_since));
                Date tempDate = new Date();
    
                companyItem.setDateUpdated(new Date());
                companyItem.setDateLastReview(new Date());
                companyItem.setDateUpdated(new Date());
    
                if (last_review_Date != null && !last_review_Date.isEmpty()) {
                    try {
                        tempDate = df.parse(last_review_Date);
                        String value = tempDate.toString();
                        companyItem.setDateLastReview(tempDate);
                    } catch (ParseException ex) {
                    }
                }
    
                companyItem.setReviewedBy(reviewed_by);
                companyItem.setModifiedBy(modified_by);
    
                CompanyItemDAO.addCompanyItem(companyItem);
    
                int adressId = companyItem.getAdressId();
                int compAddedId = companyItem.getAdressId();
                AdressItem adressItem = null;
                if (adressId <= 0) {
                    adressItem = new AdressItem();
                    adressItem.setCompanyId(companyItem.getId());
                    adressItem.setStreet1(street1);
                    adressItem.setStreet1(street2);
                    adressItem.setCity(city);
                    adressItem.setZip(zipcode);
                    adressItem.setStateregionname(state_province);
                    adressItem.setMail(mail);
                    // countryId
                    if (country != "") {
                        CountryItem countryItemTemp = CountryItemDAO.getCountryItemByName(country);
                        adressItem.setCountryId(countryItemTemp.getId());
                    }
                    AdressItemDAO.addAdressItem(adressItem);
    
                    if (telephone != "")
                        AdressItemDAO.updatePhoneItem(adressItem, telephone, 1);
                    if (telefax != "")
                        AdressItemDAO.updatePhoneItem(adressItem, telefax, 2);
                    AdressItemDAO.updateAdressItem(adressItem);
                }
    
                //2 . SAP solution focus
                if (SAPitems != null) {
                    for (int loopIndex = 0; loopIndex < SAPitems.length; loopIndex++) {
                        System.out.println(SAPitems[loopIndex]);
                    }
                }
                CompanyUtil.updateCompanySAPSolutionList(companyItem, SAPitems);
                // 3. Industry
                if (industry != null) {
                    for (int loopIndex = 0; loopIndex < industry.length; loopIndex++) {
                        System.out.println(industry[loopIndex]);
                    }
                }
                CompanyUtil.updateCompanyIndustriesList(companyItem, industry);
                //4. primary business type -- primary_business_type
                if (primary_business_type != null)
                    CompanyUtil.updateBusinessType(companyItem, primary_business_type, 1);
                //5. secondary business type - secondary_business_type
                if (secondary_business_type != null)
                    CompanyUtil.updateBusinessType(companyItem, secondary_business_type, 2);
                //6. country coverage
    
                if (countryCoverage != null) {
                    for (int loopIndex = 0; loopIndex < countryCoverage.length; loopIndex++) {
                        System.out.println(countryCoverage[loopIndex]);
                    }
                }
                CompanyUtil.updateCompanyCountryCoverage(companyItem, countryCoverage);
    
            } else if (command.equals("edit")) {
                //user
                CompanyItem companyItem = CompanyItemDAO.getCompanyItem(id);
    
                companyItem.setName(userCompanyName);
                companyItem.setDescription(partnerDescription);
                companyItem.setCompanyNo(partnerNumber);
                companyItem.setCompanyFriendlySite(micrositeAdress);
                companyItem.setCompanySite(company_website);
                if (noemployees != null && !noemployees.isEmpty())
                    companyItem.setCompanyEmpNo(Integer.parseInt(noemployees));
                companyItem.setParentCompanyName(parent_company_name);
                if (channel_partner_since != null && !channel_partner_since.isEmpty())
                    companyItem.setYear(Integer.parseInt(channel_partner_since));
                if (country_parent_company != "") {
                    CountryItem countryItemTemp = CountryItemDAO.getCountryItemByName(country_parent_company);
                    if (countryItemTemp != null)
                        companyItem.setCountryRegistrationId(countryItemTemp.getId());
                }
    
                Date date = new Date();
                try {
                    date = df.parse(last_review_Date);
                } catch (ParseException ex) {
                }
                /*companyItem.setDateLastReview(date);
                try {date = df.parse(profile_added);
                }catch (ParseException ex){
                }
                companyItem.setDateCreated(date);*/
                companyItem.setDateUpdated(new Date());
                companyItem.setReviewedBy(reviewed_by);
                companyItem.setModifiedBy(modified_by);
    
                // update childs
                //1 . adress + phone
                int adressId = companyItem.getAdressId();
                AdressItem adressItem = null;
                boolean bIsNew = false;
                if (adressId > 0) {
                    adressItem = AdressItemDAO.getAdressItem(adressId);
                } else {
                    adressItem = new AdressItem();
                    bIsNew = true;
                }
                if (adressItem != null) {
                    adressItem.setCompanyId(id);
                    adressItem.setStreet1(street1);
                    adressItem.setStreet2(street2);
                    adressItem.setCity(city);
                    adressItem.setZip(zipcode);
                    adressItem.setStateregionname(state_province);
                    adressItem.setMail(mail);
                    // countryId
                    if (country != "") {
                        CountryItem countryItemTemp = CountryItemDAO.getCountryItemByName(country);
                        adressItem.setCountryId(countryItemTemp.getId());
                    }
    
                    if (bIsNew) {
                        AdressItemDAO.addAdressItem(adressItem);
                        companyItem.setAdressId(adressItem.getId());
                    }
                    if (telephone != "")
                        AdressItemDAO.updatePhoneItem(adressItem, telephone, 1);
                    if (telefax != "")
                        AdressItemDAO.updatePhoneItem(adressItem, telefax, 2);
                    AdressItemDAO.updateAdressItem(adressItem);
                }
                // Do update in main table
                CompanyItemDAO.updateCompanyItem(companyItem);
    
                //2 . SAP solution focus
                if (SAPitems != null) {
                    for (int loopIndex = 0; loopIndex < SAPitems.length; loopIndex++) {
                        System.out.println(SAPitems[loopIndex]);
                    }
                }
                CompanyUtil.updateCompanySAPSolutionList(companyItem, SAPitems);
                // 3. Industry
                if (industry != null) {
                    for (int loopIndex = 0; loopIndex < industry.length; loopIndex++) {
                        System.out.println(industry[loopIndex]);
                    }
                }
                CompanyUtil.updateCompanyIndustriesList(companyItem, industry);
                //4. primary business type -- primary_business_type
                if (primary_business_type != null)
                    CompanyUtil.updateBusinessType(companyItem, primary_business_type, 1);
                //5. secondary business type - secondary_business_type
                if (secondary_business_type != null)
                    CompanyUtil.updateBusinessType(companyItem, secondary_business_type, 2);
                //6. country coverage
    
                if (countryCoverage != null) {
                    for (int loopIndex = 0; loopIndex < countryCoverage.length; loopIndex++) {
                        System.out.println(countryCoverage[loopIndex]);
                    }
                }
                CompanyUtil.updateCompanyCountryCoverage(companyItem, countryCoverage);
            } else if (command.equals("delete")) {
                CompanyItemDAO.deleteCompanyItem(id);
            } else if (command.equals("search")) {
                ;
            } else if (command.equals("viewall")) {
                ;
            }
            System.out.println("iese");
        } catch (SQLException sqle) {
            throw new PortletException(sqle);
        }
    
    }