1 41 package com.mvnforum.admin; 42 43 import java.io.*; 44 import java.sql.Timestamp ; 45 import java.util.*; 46 47 import javax.servlet.ServletContext ; 48 49 import com.mvnforum.*; 50 import com.mvnforum.auth.*; 51 import com.mvnforum.db.CompanyBean; 52 import com.mvnforum.db.DAOFactory; 53 import com.mvnforum.search.company.CompanyIndexer; 54 import com.mvnforum.search.company.CompanySearchQuery; 55 import net.myvietnam.mvncore.exception.*; 56 import net.myvietnam.mvncore.util.*; 57 import net.myvietnam.mvncore.web.*; 58 import net.myvietnam.mvncore.web.fileupload.FileItem; 59 import net.myvietnam.mvncore.web.fileupload.FileUploadException; 60 import org.apache.commons.logging.Log; 61 import org.apache.commons.logging.LogFactory; 62 63 public class CompanyWebHandler { 64 65 private static Log log = LogFactory.getLog(CompanyWebHandler.class); 66 67 private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance(); 68 69 public CompanyWebHandler() { 70 } 71 72 public void processAdd(GenericRequest request) 73 throws BadInputException, ObjectNotFoundException, CreateException, DatabaseException, DuplicateKeyException, 74 ForeignKeyNotFoundException, AuthenticationException, AssertionException, IOException { 75 76 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 77 MVNForumPermission permission = onlineUser.getPermission(); 78 permission.ensureCanAdminSystem(); 79 80 Timestamp now = DateUtil.getCurrentGMTTimestamp(); 81 82 String companyName = GenericParamUtil.getParameterSafe(request, "CompanyName", true); 83 String companyAddress = GenericParamUtil.getParameterSafe(request, "CompanyAddress", false); 84 String companyCity = GenericParamUtil.getParameterSafe(request, "CompanyCity", false); 85 String companyCAP = GenericParamUtil.getParameterSafe(request, "CompanyCAP", false); 86 String companyProvince = GenericParamUtil.getParameterSafe(request, "CompanyProvince", false); 87 String companyRegion = GenericParamUtil.getParameterSafe(request, "CompanyRegion", false); 88 String companyPhone = GenericParamUtil.getParameterSafe(request, "CompanyPhone", false); 89 String companyFax = GenericParamUtil.getParameterSafe(request, "CompanyFax", false); 90 String companyWebsite = GenericParamUtil.getParameterUrl(request, "CompanyWebsite"); 91 String companyEmail = GenericParamUtil.getParameterEmail(request, "CompanyEmail"); 92 String companySpaceName = GenericParamUtil.getParameterSafe(request, "CompanySpaceName", true); 93 String companySpaceHeader = GenericParamUtil.getParameterSafe(request, "CompanySpaceHeader", false); 94 String companySpaceFooter = GenericParamUtil.getParameterSafe(request, "CompanySpaceFooter", false); 95 String companyVATNumber = GenericParamUtil.getParameterSafe(request, "CompanyVATNumber", true); 96 String companyLogo = ""; 97 String companyCss = ""; 98 Timestamp companyCreationDate = now; 99 Timestamp companyModifiedDate = now; 100 101 try { 103 DAOFactory.getCompanyDAO().findByAlternateKey_CompanyName(companyName); 105 throw new DuplicateKeyException("Alternate key already exists. Cannot create new Company with the same <CompanyName> (" + companyName + ")."); 107 } catch(ObjectNotFoundException e) { 108 } 110 111 try { 112 DAOFactory.getCompanyDAO().findByAlternateKey_CompanyEmail(companyEmail); 114 throw new DuplicateKeyException("Alternate key already exists. Cannot create new Company with the same <CompanyEmail> (" + companyEmail + ")."); 116 } catch(ObjectNotFoundException e) { 117 } 119 120 try { 121 DAOFactory.getCompanyDAO().findByAlternateKey_CompanySpaceName(companySpaceName); 123 throw new DuplicateKeyException("Alternate key already exists. Cannot create new Company with the same <CompanySpaceName> (" + companySpaceName + ")."); 125 } catch(ObjectNotFoundException e) { 126 } 128 129 String groupName = MVNForumGlobal.COMPANY_GROUP_FREFIX + companyName; 131 String groupDesc = "This is the default generated group for company " + companyName; 132 int groupOption = 0; 134 DAOFactory.getGroupsDAO().create("", groupName, groupDesc, 135 groupOption, now, now); 136 137 int groupID = DAOFactory.getGroupsDAO().getGroupIDFromGroupName(groupName); 138 139 DAOFactory.getCompanyDAO().create(groupID, companyName, companyAddress, 141 companyCity, companyCAP, companyProvince, 142 companyRegion, companyPhone, companyFax, 143 companyWebsite, companyEmail, companySpaceName, 144 companySpaceHeader, companySpaceFooter, companyVATNumber, 145 companyLogo, companyCss, companyCreationDate, 146 companyModifiedDate); 147 148 int companyID = DAOFactory.getCompanyDAO().getCompanyIDFromCompanyEmail(companyEmail); 150 151 StringBuffer bufferCompanyFolder = new StringBuffer (128); 152 bufferCompanyFolder.append(request.getRealPath(MVNForumGlobal.UPLOADED_COMPANY_DIR)); 153 bufferCompanyFolder.append(File.separatorChar).append(companyID); 154 String companyFolder = bufferCompanyFolder.toString(); 155 FileUtil.createDir(companyFolder, true); 156 157 CompanyBean justAddedCompanyBean = null; 159 try { 160 justAddedCompanyBean = DAOFactory.getCompanyDAO().getCompany(companyID); 161 } catch (ObjectNotFoundException e) { 162 Locale locale = I18nUtil.getLocaleInRequest(request); 163 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object [] {new Integer (companyID)}); 164 throw new ObjectNotFoundException(localizedMessage); 165 } 166 167 CompanyIndexer.scheduleAddCompanyTask(justAddedCompanyBean); 168 } 169 170 public void prepareView(GenericRequest request) 171 throws BadInputException, ObjectNotFoundException, DatabaseException, 172 AssertionException, AuthenticationException { 173 174 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 175 MVNForumPermission permission = onlineUser.getPermission(); 176 permission.ensureCanAdminSystem(); 177 178 String strCompanyID = GenericParamUtil.getParameter(request, "companyid", false); 179 String strCompanyEmail = GenericParamUtil.getParameter(request, "companyemail", false); 180 String strCompanyCreationDate = GenericParamUtil.getParameter(request, "companycreationdate", false); 181 182 int companyID = 0; 183 184 Locale locale = I18nUtil.getLocaleInRequest(request); 185 186 if (strCompanyID.length() > 0) { 187 companyID = GenericParamUtil.getParameterInt(request, "companyid"); 188 } else if (strCompanyEmail.length() > 0) { 189 String companyEmail = GenericParamUtil.getParameterEmail(request, "companyemail"); try { 191 companyID = DAOFactory.getCompanyDAO().getCompanyIDFromCompanyEmail(companyEmail); 192 } catch (ObjectNotFoundException e) { 193 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.company_not_exists.with_email", new Object [] {companyEmail}); 194 throw new ObjectNotFoundException(localizedMessage); 195 } 196 } else if (strCompanyCreationDate.length() > 0) { 197 java.util.Date companyCreationDate = GenericParamUtil.getParameterDateUtil(request, "companycreationdate"); 198 try { 199 companyID = DAOFactory.getCompanyDAO().getCompanyIDFromCompanyCreationDate(companyCreationDate); 200 } catch (ObjectNotFoundException e) { 201 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.company_not_exists.with_creationdate", new Object [] {strCompanyCreationDate}); 202 throw new ObjectNotFoundException(localizedMessage); 203 } 204 } else { 205 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_get_info_to_view_company"); 206 throw new BadInputException(localizedMessage); 207 } 209 CompanyBean companyBean = null; 210 try { 211 companyBean = DAOFactory.getCompanyDAO().getCompany(companyID); 212 } catch (ObjectNotFoundException e) { 213 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object [] {new Integer (companyID)}); 214 throw new ObjectNotFoundException(localizedMessage); 215 } 216 217 request.setAttribute("CompanyBean", companyBean); 218 } 219 220 public void processUpdateCompanyInfo(GenericRequest request) 221 throws BadInputException, DatabaseException, ObjectNotFoundException, 222 DuplicateKeyException, AuthenticationException, AssertionException { 223 224 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 225 MVNForumPermission permission = onlineUser.getPermission(); 226 permission.ensureCanAdminSystem(); 227 228 Timestamp now = DateUtil.getCurrentGMTTimestamp(); 229 230 int companyID = GenericParamUtil.getParameterInt(request,"companyid"); 231 String companyName = GenericParamUtil.getParameterSafe(request, "CompanyName", true); 232 String companyAddress = GenericParamUtil.getParameterSafe(request, "CompanyAddress", false); 233 String companyCity = GenericParamUtil.getParameterSafe(request, "CompanyCity", false); 234 String companyCAP = GenericParamUtil.getParameterSafe(request, "CompanyCAP", false); 235 String companyProvince = GenericParamUtil.getParameterSafe(request, "CompanyProvince", false); 236 String companyRegion = GenericParamUtil.getParameterSafe(request, "CompanyRegion", false); 237 String companyPhone = GenericParamUtil.getParameterSafe(request, "CompanyPhone", false); 238 String companyFax = GenericParamUtil.getParameterSafe(request, "CompanyFax", false); 239 String companyWebsite = GenericParamUtil.getParameterUrl(request, "CompanyWebsite"); 240 String companyEmail = GenericParamUtil.getParameterEmail(request, "CompanyEmail"); 241 String companySpaceName = GenericParamUtil.getParameterSafe(request, "CompanySpaceName", true); 242 String companySpaceHeader = GenericParamUtil.getParameterSafe(request,"CompanySpaceHeader", false); 243 String companySpaceFooter = GenericParamUtil.getParameterSafe(request, "CompanySpaceFooter", false); 244 String companyVATNumber = GenericParamUtil.getParameterSafe(request, "CompanyVATNumber", true); 245 246 DAOFactory.getCompanyDAO().updateCompanyInfo(companyID, 247 companyName, 248 companyAddress, 249 companyCity, 250 companyCAP, 251 companyProvince, 252 companyRegion, 253 companyPhone, 254 companyFax, 255 companyWebsite, 256 companyEmail, 257 companySpaceName, 258 companySpaceHeader, 259 companySpaceFooter, 260 companyVATNumber, 261 now); 262 CompanyBean companyBean = null; 263 try { 264 companyBean = DAOFactory.getCompanyDAO().getCompany(companyID); 265 } catch (ObjectNotFoundException e) { 266 Locale locale = I18nUtil.getLocaleInRequest(request); 267 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object [] {new Integer (companyID)}); 268 throw new ObjectNotFoundException(localizedMessage); 269 } 270 request.setAttribute("CompanyBean", companyBean); 271 272 int groupID = companyBean.getGroupID(); 274 String groupName = MVNForumGlobal.COMPANY_GROUP_FREFIX + companyName; 275 String groupDesc = "This is the default generated group for company " + companyName; 276 277 DAOFactory.getGroupsDAO().update(groupID, groupName, groupDesc, now); 278 279 CompanyIndexer.scheduleUpdateCompanyTask(companyBean); 281 } 282 283 public void processChangeLogo(ServletContext context, GenericRequest request) 284 throws BadInputException, AuthenticationException, IOException, 285 AssertionException, ObjectNotFoundException, DatabaseException { 286 287 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 288 MVNForumPermission permission = onlineUser.getPermission(); 289 permission.ensureCanAdminSystem(); 290 291 Locale locale = I18nUtil.getLocaleInRequest(request); 292 293 int companyID = GenericParamUtil.getParameterInt(request, "companyid"); 295 296 int sizeMax = 70000; int sizeThreshold = 100000; List fileItems; 299 try { 300 FileUploadParser uploadParser = FileUploadParserFactory.getFileUploadParser(); 301 fileItems = uploadParser.parseRequest(request, sizeMax, sizeThreshold, null, "UTF-8"); 302 } catch (FileUploadException ex) { 303 log.error("Cannot upload", ex); 304 String localizedMessage = MVNForumResourceBundle.getString(locale, "java.io.IOException.cannot_upload", new Object [] {ex.getMessage()}); 305 throw new IOException(localizedMessage); 306 } 308 309 if (fileItems.size() != 1) { 311 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_upload_more_than_one", new Object [] {"logo"}); 312 throw new AssertionException(localizedMessage); 313 } 315 316 FileItem myFile = (FileItem)fileItems.get(0); 318 if (myFile.isFormField() == true) { 319 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_process_uploaded_file_with_a_form_field", new Object [] {"logo"}); 320 throw new AssertionException(localizedMessage); 321 } 323 324 InputStream inputStream = myFile.getInputStream(); 326 327 StringBuffer bufferPicFile = new StringBuffer (128); 328 bufferPicFile.append(request.getRealPath(MVNForumGlobal.UPLOADED_COMPANY_DIR)); 329 bufferPicFile.append(File.separatorChar).append(companyID); 330 331 String companyDir = bufferPicFile.toString(); 332 FileUtil.createDirs(companyDir, true); 333 334 bufferPicFile.append("/").append("logo.jpg"); 335 String logoFile = bufferPicFile.toString(); 336 337 log.trace("uploaded file = " + logoFile); 338 339 ImageUtil.createThumbnail(inputStream, logoFile, 500, 500); 342 StringBuffer bufferVirtualFile = new StringBuffer (128); 344 bufferVirtualFile.append(MVNForumGlobal.UPLOADED_COMPANY_DIR); 345 bufferVirtualFile.append("/").append(companyID).append("/").append("logo.jpg"); 346 String virtualFile = bufferVirtualFile.toString(); 347 348 try { 349 DAOFactory.getCompanyDAO().updateCompanyLogo(companyID, virtualFile); 350 } catch (DatabaseException ex) { log.fatal("Assertion in CompanyWebHandler.processChangeLogo"); FileUtil.deleteFile(logoFile); 354 throw ex; 355 } 356 CompanyBean companyBean = null; 357 try { 358 companyBean = DAOFactory.getCompanyDAO().getCompany(companyID); 359 } catch (ObjectNotFoundException e) { 360 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object [] {new Integer (companyID)}); 361 throw new ObjectNotFoundException(localizedMessage); 362 } 363 request.setAttribute("CompanyBean", companyBean); 364 } 365 366 public void processChangeCss(ServletContext context, GenericRequest request) 367 throws BadInputException, AuthenticationException, IOException, 368 AssertionException, ObjectNotFoundException, DatabaseException { 369 370 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 371 MVNForumPermission permission = onlineUser.getPermission(); 372 permission.ensureCanAdminSystem(); 373 374 Locale locale = I18nUtil.getLocaleInRequest(request); 375 376 int companyID = GenericParamUtil.getParameterInt(request, "companyid"); 378 379 int sizeMax = 20000; int sizeThreshold = 100000; List fileItems; 382 try { 383 FileUploadParser uploadParser = FileUploadParserFactory.getFileUploadParser(); 384 fileItems = uploadParser.parseRequest(request, sizeMax, sizeThreshold, null, "UTF-8"); 385 } catch (FileUploadException ex) { 386 log.error("Cannot upload", ex); 387 String localizedMessage = MVNForumResourceBundle.getString(locale, "java.io.IOException.cannot_upload", new Object [] {ex.getMessage()}); 388 throw new IOException(localizedMessage); 389 } 391 392 if (fileItems.size() != 1) { 394 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_upload_more_than_one", new Object [] {"css"}); 395 throw new AssertionException(localizedMessage); 396 } 398 399 FileItem myFile = (FileItem)fileItems.get(0); 401 if (myFile.isFormField() == true) { 402 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_process_uploaded_file_with_a_form_field", new Object [] {"css"}); 403 throw new AssertionException(localizedMessage); 404 } 406 407 InputStream inputStream = myFile.getInputStream(); 409 StringBuffer bufferCssFile = new StringBuffer (128); 410 bufferCssFile.append(context.getRealPath(MVNForumGlobal.UPLOADED_COMPANY_DIR)); 411 bufferCssFile.append(File.separatorChar).append(companyID); 412 413 String companyDir = bufferCssFile.toString(); 414 FileUtil.createDirs(companyDir, true); 415 416 bufferCssFile.append("/").append("style.css"); 417 String cssFile = bufferCssFile.toString(); 418 419 log.trace("uploaded file = " + cssFile); 420 421 FileUtil.createTextFile(inputStream, cssFile); 424 StringBuffer bufferVirtualFile = new StringBuffer (128); 426 bufferVirtualFile.append(MVNForumGlobal.UPLOADED_COMPANY_DIR); 427 bufferVirtualFile.append("/").append(companyID).append("/").append("style.css"); 428 String virtualFile = bufferVirtualFile.toString(); 429 430 try { 431 DAOFactory.getCompanyDAO().updateCompanyCss(companyID, virtualFile); 432 } catch (DatabaseException ex) { log.fatal("Assertion in CompanyWebHandler.processChangeCss"); FileUtil.deleteFile(cssFile); 436 throw ex; 437 } 438 CompanyBean companyBean = null; 439 try { 440 companyBean = DAOFactory.getCompanyDAO().getCompany(companyID); 441 } catch (ObjectNotFoundException e) { 442 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object [] {new Integer (companyID)}); 443 throw new ObjectNotFoundException(localizedMessage); 444 } 445 request.setAttribute("CompanyBean", companyBean); 446 } 447 448 public void prepare(GenericRequest request) 449 throws ObjectNotFoundException, BadInputException, DatabaseException, AuthenticationException, AssertionException { 450 451 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 452 MVNForumPermission permission = onlineUser.getPermission(); 453 permission.ensureCanAdminSystem(); 454 455 int companyID = GenericParamUtil.getParameterInt(request, "companyid"); 456 457 CompanyBean companyBean = null; 458 try { 459 companyBean = DAOFactory.getCompanyDAO().getCompany(companyID); 460 } catch (ObjectNotFoundException e) { 461 Locale locale = I18nUtil.getLocaleInRequest(request); 462 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object [] {new Integer (companyID)}); 463 throw new ObjectNotFoundException(localizedMessage); 464 } 465 request.setAttribute("CompanyBean", companyBean); 466 } 467 468 public void processDelete(ServletContext context, GenericRequest request) 469 throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException, AssertionException { 470 471 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 472 MVNForumPermission permission = onlineUser.getPermission(); 473 permission.ensureCanAdminSystem(); 474 475 int companyID = GenericParamUtil.getParameterInt(request, "companyid"); 477 478 MyUtil.ensureCorrectCurrentPassword(request); 480 481 try { 482 DAOFactory.getCompanyDAO().delete(companyID); 483 } catch (ObjectNotFoundException e ) { 484 Locale locale = I18nUtil.getLocaleInRequest(request); 485 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object [] {new Integer (companyID)}); 486 throw new ObjectNotFoundException(localizedMessage); 487 } 488 DAOFactory.getMemberCompanyDAO().delete_inCompany(companyID); 489 490 StringBuffer bufferCompanyFolder = new StringBuffer (128); 492 bufferCompanyFolder.append(context.getRealPath(MVNForumGlobal.UPLOADED_COMPANY_DIR)); 493 bufferCompanyFolder.append(File.separatorChar).append(companyID); 494 String companyFolder = bufferCompanyFolder.toString(); 495 try { 496 FileUtil.deleteDir(new File(companyFolder)); 497 } catch (IOException ioe) { 498 } 499 500 CompanyIndexer.scheduleDeleteCompanyTask(companyID); 502 } 503 504 507 public void prepareShowCompanyManagement(GenericRequest request) 508 throws DatabaseException, AssertionException, BadInputException, AuthenticationException { 509 510 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 511 MVNForumPermission permission = onlineUser.getPermission(); 512 permission.ensureCanAdminSystem(); 513 514 String sort = GenericParamUtil.getParameter(request, "sort"); 516 String order = GenericParamUtil.getParameter(request, "order"); 517 if (sort.length() == 0) sort = "CompanyCreationDate"; 518 if (order.length()== 0) order = "DESC"; 519 520 int postsPerPage = onlineUser.getPostsPerPage(); 522 int offset = 0; 523 try { 524 offset = GenericParamUtil.getParameterInt(request, "offset"); 525 } catch (BadInputException e) { 526 } 528 529 Locale locale = I18nUtil.getLocaleInRequest(request); 530 531 int totalCompanies = DAOFactory.getCompanyDAO().getNumberOfCompanies(); 532 if (offset > totalCompanies) { 533 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows"); 534 throw new BadInputException(localizedMessage); 535 } 537 538 Collection companyBeans = DAOFactory.getCompanyDAO().getCompanies_withSortSupport_limit(offset, postsPerPage, sort, order); 539 540 request.setAttribute("CompanyBeans", companyBeans); 541 request.setAttribute("TotalCompanies", new Integer (totalCompanies)); 542 request.setAttribute("offset", new Integer (offset)); 543 } 544 545 public void processSearch(GenericRequest request) 546 throws BadInputException, IOException, DatabaseException, ObjectNotFoundException, 547 AuthenticationException, AssertionException { 548 549 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 550 MVNForumPermission permission = onlineUser.getPermission(); 551 permission.ensureCanAdminSystem(); 552 553 String companyNameKey = GenericParamUtil.getParameter(request, "companyname", false); 554 String companyAddressKey = GenericParamUtil.getParameter(request, "companyaddress", false); 555 String companyDateKey = GenericParamUtil.getParameter(request, "companycreationdate", false); 556 557 Locale locale = I18nUtil.getLocaleInRequest(request); 558 559 int defaultRows = onlineUser.getPostsPerPage(); 560 561 int offset = GenericParamUtil.getParameterUnsignedInt(request, "offset", 0); 562 int rows = GenericParamUtil.getParameterUnsignedInt(request, "rows", defaultRows); 563 if (rows == 0) { 564 rows = defaultRows; } 566 567 offset = (offset / rows) * rows; 569 570 CompanySearchQuery query = new CompanySearchQuery(); 571 572 if (companyNameKey.length() > 0) { 573 query.setCompanyNameKey(companyNameKey); 574 } else if (companyAddressKey.length() > 0){ 575 query.setCompanyAddressKey(companyAddressKey); 576 } else { 577 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_search.key_is_null"); 578 throw new BadInputException(localizedMessage); 579 } 580 586 587 int searchDate = GenericParamUtil.getParameterUnsignedInt(request, "date", CompanySearchQuery.SEARCH_ANY_DATE); 588 int searchBeforeAfter = GenericParamUtil.getParameterInt(request, "beforeafter", CompanySearchQuery.SEARCH_NEWER); 589 590 if ((searchDate != CompanySearchQuery.SEARCH_ANY_DATE) && (searchDate < 365 * 10)) { long deltaTime = DateUtil.DAY * searchDate; 592 593 Timestamp now = DateUtil.getCurrentGMTTimestamp(); 594 Timestamp from = null; 595 Timestamp to = null; 596 597 long currentTime = now.getTime(); 598 599 if (searchBeforeAfter == CompanySearchQuery.SEARCH_NEWER) { 600 from = new Timestamp (currentTime - deltaTime); 601 } else { to = new Timestamp (currentTime - deltaTime); 603 } 604 605 query.setFromCompanyDateKey(from); 606 query.setToCompanyDateKey(to); 607 } 608 609 610 query.searchDocuments(offset, rows); 611 int hitCount = query.getHitCount(); 612 Collection result = query.getCompanyResult(); 613 614 if (offset > hitCount) { 615 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows"); 616 throw new BadInputException(localizedMessage); 617 } 618 619 request.setAttribute("offset", new Integer (offset)); 620 request.setAttribute("rows", new Integer (rows)); 621 request.setAttribute("TotalCompanies", new Integer (hitCount)); 622 request.setAttribute("CompanyBeans", result); 623 request.setAttribute("CompanyName", companyNameKey); 624 request.setAttribute("CompanyAddress", companyAddressKey); request.setAttribute("CompanyCreationDate",companyDateKey); request.setAttribute("CompanyModifiedDate", ""); request.setAttribute("FromCompanyCreationDate", ""); request.setAttribute("ToCompanyCreationDate", ""); } 630 } 631 | Popular Tags |