List of usage examples for java.sql Timestamp valueOf
@SuppressWarnings("deprecation") public static Timestamp valueOf(LocalDateTime dateTime)
From source file:at.ac.tuwien.qse.sepm.dao.impl.JDBCPhotoDAO.java
@Override public Photo create(Photo photo) throws DAOException { if (photo == null) throw new IllegalArgumentException(); logger.debug("Creating photo {}", photo); Map<String, Object> parameters = new HashMap<String, Object>(1); parameters.put("path", photo.getPath()); parameters.put("rating", photo.getData().getRating().ordinal()); parameters.put("datetime", Timestamp.valueOf(photo.getData().getDatetime())); parameters.put("latitude", photo.getData().getLatitude()); parameters.put("longitude", photo.getData().getLongitude()); Place place = photo.getData().getPlace(); parameters.put("place_id", null); if (place != null) { parameters.put("place_id", place.getId()); }//from ww w . jav a 2s . c om Journey journey = photo.getData().getJourney(); parameters.put("journey_id", null); if (journey != null) { parameters.put("journey_id", journey.getId()); } Photographer photographer = photo.getData().getPhotographer(); parameters.put("photographer_id", null); if (photographer != null) { parameters.put("photographer_id", photographer.getId()); } try { Number newId = insertPhoto.executeAndReturnKey(parameters); photo.setId((int) newId.longValue()); return photo; } catch (DataAccessException ex) { logger.error("Failed to create photo", ex); throw new DAOException("Failed to create photo", ex); } }
From source file:cn.com.sinosoft.ebusiness.log.LoggingEventWrapper.java
public Date getBeginTime() { if ("1".equals(getLogType())) { try {//from ww w.j a v a 2s. c o m String message = getMessage(); Timestamp beginTime = Timestamp.valueOf(message.split("--")[1]); return beginTime; } catch (Exception e) { logger.warn("err eventwrpper get begintime"); } } return null; }
From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportEmployeeUnitsFromGiaf.java
private List<Modification> importIt(PersistentSuportGiaf oracleConnection, GiafMetadata metadata, LocalDate today, String query, AccountabilityTypeEnum accountabilityTypeEnum, PrintWriter log, Logger logger) throws SQLException { List<Modification> modifications = new ArrayList<>(); PreparedStatement preparedStatement = oracleConnection.prepareStatement(query); ResultSet result = preparedStatement.executeQuery(); while (result.next()) { String employeeNumber = result.getString("emp_num"); Employee employee = metadata.getEmployee(employeeNumber, logger); if (employee == null) { log.println(accountabilityTypeEnum.getName() + ". No existe funcionrio. Nmero: " + employeeNumber);//from ww w .j av a 2 s . c o m continue; } Integer costCenterCode = 0; try { costCenterCode = result.getInt("cc"); } catch (SQLException e) { log.println(accountabilityTypeEnum.getName() + ". CC invlido. Nmero: " + employeeNumber); continue; } Unit unit = costCenterCode.intValue() == 0 ? null : Unit.readByCostCenterCode(costCenterCode); String ccDateString = result.getString("cc_date"); LocalDate beginDate = today; if (!StringUtils.isEmpty(ccDateString)) { beginDate = new LocalDate(Timestamp.valueOf(ccDateString)); } if (unit != null || costCenterCode.intValue() == 0) { if (employee.getPerson().getPersonProfessionalData() != null) { GiafProfessionalData giafProfessionalDataByGiafPersonIdentification = employee.getPerson() .getPersonProfessionalData() .getGiafProfessionalDataByGiafPersonIdentification(employeeNumber); ContractSituation contractSituation = giafProfessionalDataByGiafPersonIdentification .getContractSituation(); if (contractSituation != null) { LocalDate endDate = null; if (contractSituation.getEndSituation()) { PersonContractSituation personContractSituation = getOtherValidPersonContractSituation( giafProfessionalDataByGiafPersonIdentification); if (personContractSituation != null) { contractSituation = personContractSituation.getContractSituation(); endDate = personContractSituation.getEndDate(); } else { endDate = giafProfessionalDataByGiafPersonIdentification.getContractSituationDate(); } } Contract workingContractOnDate = getLastContractByContractType(employee, accountabilityTypeEnum, new YearMonthDay(beginDate), endDate == null ? null : new YearMonthDay(endDate)); if (workingContractOnDate != null) { if (unit != null && endDate == null) { if (!workingContractOnDate.getUnit().equals(unit)) { modifications.addAll(createEmployeeContract(employee, new YearMonthDay(beginDate), null, unit, accountabilityTypeEnum, workingContractOnDate, log, logger)); } else if (!workingContractOnDate.getBeginDate().equals(beginDate) && !StringUtils.isEmpty(ccDateString)) { modifications.add(changeEmployeeContractDates(accountabilityTypeEnum, new YearMonthDay(beginDate), workingContractOnDate, log, logger)); } else if (workingContractOnDate.getEndDate() != null && contractSituation != null && giafProfessionalDataByGiafPersonIdentification .getContractSituationDate() != null) { log.println(accountabilityTypeEnum.getName() + ". Contrato do Funcionrio:" + employeeNumber + " Voltou a abrir na mesma unidade :" + giafProfessionalDataByGiafPersonIdentification .getContractSituationDate()); modifications.addAll(createEmployeeContract(employee, new YearMonthDay(giafProfessionalDataByGiafPersonIdentification .getContractSituationDate()), null, unit, accountabilityTypeEnum, null, log, logger)); } else { log.println(accountabilityTypeEnum.getName() + ". No h alteraes para o funcionrio:" + employeeNumber); } } else if (endDate != null) { // terminou o contrato corrente modifications .add(closeCurrentContract(accountabilityTypeEnum, workingContractOnDate, new YearMonthDay(endDate.minusDays(1)), log, logger)); } } else { if (unit != null && endDate == null) { // contrato novo modifications.addAll(createEmployeeContract(employee, new YearMonthDay(beginDate), null, unit, accountabilityTypeEnum, null, log, logger)); } else { // j tinha terminado o contrato e j // terminou // tb do nosso lado // log.println(accountabilityTypeEnum.getName() // + ". Contrato terminado na unidade " // + unit.getName() + " para o funcionrio:" // + employeeNumber + " (no fez nada)"); } } } else { log.println("ERRO... no tem situao no GIAF " + employeeNumber); Contract currentWorkingContract = employee .getCurrentContractByContractType(accountabilityTypeEnum); if (currentWorkingContract != null) { LocalDate endDate = today.minusDays(1); closeCurrentContract(accountabilityTypeEnum, currentWorkingContract, new YearMonthDay(endDate), log, logger); log.println(accountabilityTypeEnum.getName() + ". No no tem contrato no GIAF, e terminamos no Fnix: " + employeeNumber); } else { log.println(accountabilityTypeEnum.getName() + ". No no tem contrato no GIAF, nem no fnix: " + employeeNumber); } } } else { log.println("No tem employeeProfessionalData. Funcionario: " + employeeNumber); } } else { log.println(accountabilityTypeEnum.getName() + ". No existe unidade: " + costCenterCode + " para o funcionario: " + employeeNumber); } } result.close(); preparedStatement.close(); return modifications; }
From source file:edumsg.core.commands.user.MyProfileCommand.java
@Override public void execute() { try {//from w w w . j a v a2s.c o m details = null; //Cache.returnUser(map.get("username")); User user = new User(); if (details == null) { dbConn = PostgresConnection.getDataSource().getConnection(); dbConn.setAutoCommit(false); proc = dbConn.prepareCall("{? = call my_profile(?)}"); proc.setPoolable(true); proc.registerOutParameter(1, Types.OTHER); proc.setString(2, map.get("session_id")); proc.execute(); set = (ResultSet) proc.getObject(1); root.put("app", map.get("app")); root.put("method", map.get("method")); root.put("status", "ok"); root.put("code", "200"); if (set.next()) { Integer id = set.getInt(1); String username = set.getString(2); String email = set.getString(3); String name = set.getString(5); String language = set.getString(6); String country = set.getString(7); String bio = set.getString(8); String website = set.getString(9); Timestamp created_at = set.getTimestamp(10); String avatar_url = set.getString(11); Boolean overlay = set.getBoolean(12); String link_color = set.getString(13); String background_color = set.getString(14); Boolean protected_tweets = set.getBoolean(15); user.setId(id); user.setUsername(username); user.setEmail(email); user.setName(name); user.setLanguage(language); user.setCountry(country); user.setBio(bio); user.setWebsite(website); user.setCreatedAt(created_at); user.setAvatarUrl(avatar_url); user.setOverlay(overlay); user.setLinkColor(link_color); user.setBackgroundColor(background_color); user.setProtectedTweets(protected_tweets); } set.close(); proc.close(); } else { user.setId(Integer.parseInt(details.get("id"))); user.setUsername(details.get("username")); user.setEmail(details.get("email")); user.setName(details.get("name")); user.setLanguage(details.get("language")); user.setCountry(details.get("country")); user.setBio(details.get("bio")); user.setWebsite(details.get("website")); user.setCreatedAt(Timestamp.valueOf(details.get("created_at"))); user.setAvatarUrl(details.get("avatar_url")); user.setOverlay(Boolean.parseBoolean(details.get("overlay"))); user.setLinkColor(details.get("link_color")); user.setBackgroundColor(details.get("background_color")); user.setProtectedTweets(Boolean.parseBoolean(details.get("protected_tweets"))); } ValueNode child = nf.pojoNode(user); root.set("user", child); try { CommandsHelp.submit(map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"), LOGGER); } catch (JsonGenerationException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (JsonMappingException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (IOException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } dbConn.commit(); } catch (PSQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (SQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); //Logger.log(Level.SEVERE, e.getMessage(), e); } finally { PostgresConnection.disconnect(set, proc, dbConn, null); } }
From source file:edumsg.core.commands.user.GetUserCommand.java
@Override public void execute() { try {/*from w ww . j av a2 s . c o m*/ details = null; //Cache.returnUser(map.get("username")); User user = new User(); if (details == null) { dbConn = PostgresConnection.getDataSource().getConnection(); dbConn.setAutoCommit(false); proc = dbConn.prepareCall("{? = call get_user(?)}"); proc.setPoolable(true); proc.registerOutParameter(1, Types.OTHER); proc.setInt(2, Integer.parseInt(map.get("user_id"))); proc.execute(); set = (ResultSet) proc.getObject(1); root.put("app", map.get("app")); root.put("method", map.get("method")); root.put("status", "ok"); root.put("code", "200"); if (set.next()) { Integer id = set.getInt(1); String username = set.getString(2); String email = set.getString(3); String name = set.getString(5); String language = set.getString(6); String country = set.getString(7); String bio = set.getString(8); String website = set.getString(9); Timestamp created_at = set.getTimestamp(10); String avatar_url = set.getString(11); Boolean overlay = set.getBoolean(12); String link_color = set.getString(13); String background_color = set.getString(14); Boolean protected_tweets = set.getBoolean(15); user.setId(id); user.setUsername(username); user.setEmail(email); user.setName(name); user.setLanguage(language); user.setCountry(country); user.setBio(bio); user.setWebsite(website); user.setCreatedAt(created_at); user.setAvatarUrl(avatar_url); user.setOverlay(overlay); user.setLinkColor(link_color); user.setBackgroundColor(background_color); user.setProtectedTweets(protected_tweets); } set.close(); proc.close(); } else { user.setId(Integer.parseInt(details.get("id"))); user.setUsername(details.get("username")); user.setEmail(details.get("email")); user.setName(details.get("name")); user.setLanguage(details.get("language")); user.setCountry(details.get("country")); user.setBio(details.get("bio")); user.setWebsite(details.get("website")); user.setCreatedAt(Timestamp.valueOf(details.get("created_at"))); user.setAvatarUrl(details.get("avatar_url")); user.setOverlay(Boolean.parseBoolean(details.get("overlay"))); user.setLinkColor(details.get("link_color")); user.setBackgroundColor(details.get("background_color")); user.setProtectedTweets(Boolean.parseBoolean(details.get("protected_tweets"))); } ValueNode child = nf.pojoNode(user); root.set("user", child); try { CommandsHelp.submit(map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"), LOGGER); } catch (JsonGenerationException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (JsonMappingException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (IOException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } dbConn.commit(); } catch (PSQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (SQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); //Logger.log(Level.SEVERE, e.getMessage(), e); } finally { PostgresConnection.disconnect(set, proc, dbConn, null); } }
From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonProfessionalContractsFromGiaf.java
@Override public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger) throws Exception { List<Modification> modifications = new ArrayList<>(); PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance(); PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery()); ResultSet result = preparedStatement.executeQuery(); int count = 0; int news = 0; int notImported = 0; int dontExist = 0; Set<Person> importedButInvalid = new HashSet<Person>(); while (result.next()) { count++;//from w ww . j a v a2 s . c o m String numberString = result.getString("emp_num"); Person person = metadata.getPerson(numberString, logger); if (person == null) { logger.debug("Invalid person with number: " + numberString); dontExist++; continue; } PersonProfessionalData personProfessionalData = person.getPersonProfessionalData(); if (personProfessionalData == null) { logger.debug("Empty employeeProfessionalData: " + numberString); dontExist++; continue; } final GiafProfessionalData giafProfessionalData = personProfessionalData .getGiafProfessionalDataByGiafPersonIdentification(numberString); if (giafProfessionalData == null) { logger.debug("Empty giafProfessionalData: " + numberString); dontExist++; continue; } final String contractSituationGiafId = result.getString("COD_CONTRATO"); final ContractSituation contractSituation = metadata.situation(contractSituationGiafId); if (contractSituation == null) { logger.debug("Empty situation: " + contractSituationGiafId + " for person number: " + numberString); importedButInvalid.add(person); } String beginDateString = result.getString("dt_inic"); final LocalDate beginDate = StringUtils.isEmpty(beginDateString) ? null : new LocalDate(Timestamp.valueOf(beginDateString)); if (beginDate == null) { logger.debug("Empty beginDate: " + numberString + " Situation: " + contractSituationGiafId); importedButInvalid.add(person); } String endDateString = result.getString("dt_fim"); final LocalDate endDate = StringUtils.isEmpty(endDateString) ? null : new LocalDate(Timestamp.valueOf(endDateString)); if (endDate != null) { if (beginDate != null && beginDate.isAfter(endDate)) { logger.debug("BeginDate after endDate. Person number:" + numberString + " begin: " + beginDate + " end:" + endDate); importedButInvalid.add(person); } } String creationDateString = result.getString("data_criacao"); if (StringUtils.isEmpty(creationDateString)) { logger.debug("Empty creationDate: " + numberString + " Situation: " + contractSituationGiafId); notImported++; continue; } final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString)); String modifiedDateString = result.getString("data_alteracao"); final DateTime modifiedDate = StringUtils.isEmpty(modifiedDateString) ? null : new DateTime(Timestamp.valueOf(modifiedDateString)); if (!hasPersonProfessionalContract(giafProfessionalData, beginDate, endDate, creationDate, modifiedDate, contractSituation, contractSituationGiafId)) { modifications.add(new Modification() { @Override public void execute() { new PersonProfessionalContract(giafProfessionalData, beginDate, endDate, contractSituation, contractSituationGiafId, creationDate, modifiedDate); } }); news++; } } result.close(); preparedStatement.close(); int deleted = 0; int totalInFenix = 0; int repeted = 0; for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) { for (final PersonProfessionalContract personProfessionalContract : giafProfessionalData .getPersonProfessionalContractsSet()) { if (personProfessionalContract.getAnulationDate() == null) { int countThisPersonProfessionalContractOnGiaf = countThisPersonProfessionalContractOnGiaf( oracleConnection, personProfessionalContract, logger); if (countThisPersonProfessionalContractOnGiaf == 0) { modifications.add(new Modification() { @Override public void execute() { personProfessionalContract.setAnulationDate(new DateTime()); } }); deleted++; } else { totalInFenix++; if (countThisPersonProfessionalContractOnGiaf > 1) { repeted += countThisPersonProfessionalContractOnGiaf - 1; } } } } } oracleConnection.closeConnection(); log.println("-- Professional Contracts --"); log.println("Total GIAF: " + count); log.println("New: " + news); log.println("Deleted: " + deleted); log.println("Not imported: " + notImported); log.println("Imported with errors: " + importedButInvalid.size()); log.println("Repeted: " + repeted); log.println("Invalid persons: " + dontExist); log.println("Total Fnix: " + totalInFenix); log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size())); log.println("Missing in Fnix: " + (count - totalInFenix)); return modifications; }
From source file:edumsg.core.commands.user.GetUser2Command.java
@Override public void execute() { try {/*from w ww .j ava2 s . c om*/ details = null; //Cache.returnUser(map.get("username")); User user = new User(); if (details == null) { dbConn = PostgresConnection.getDataSource().getConnection(); dbConn.setAutoCommit(false); proc = dbConn.prepareCall("{? = call get_user2(?)}"); proc.setPoolable(true); proc.registerOutParameter(1, Types.OTHER); proc.setString(2, map.get("username")); proc.execute(); set = (ResultSet) proc.getObject(1); root.put("app", map.get("app")); root.put("method", map.get("method")); root.put("status", "ok"); root.put("code", "200"); if (set.next()) { Integer id = set.getInt(1); String username = set.getString(2); String email = set.getString(3); String name = set.getString(5); String language = set.getString(6); String country = set.getString(7); String bio = set.getString(8); String website = set.getString(9); Timestamp created_at = set.getTimestamp(10); String avatar_url = set.getString(11); Boolean overlay = set.getBoolean(12); String link_color = set.getString(13); String background_color = set.getString(14); Boolean protected_tweets = set.getBoolean(15); user.setId(id); user.setUsername(username); user.setEmail(email); user.setName(name); user.setLanguage(language); user.setCountry(country); user.setBio(bio); user.setWebsite(website); user.setCreatedAt(created_at); user.setAvatarUrl(avatar_url); user.setOverlay(overlay); user.setLinkColor(link_color); user.setBackgroundColor(background_color); user.setProtectedTweets(protected_tweets); } set.close(); proc.close(); } else { user.setId(Integer.parseInt(details.get("id"))); user.setUsername(details.get("username")); user.setEmail(details.get("email")); user.setName(details.get("name")); user.setLanguage(details.get("language")); user.setCountry(details.get("country")); user.setBio(details.get("bio")); user.setWebsite(details.get("website")); user.setCreatedAt(Timestamp.valueOf(details.get("created_at"))); user.setAvatarUrl(details.get("avatar_url")); user.setOverlay(Boolean.parseBoolean(details.get("overlay"))); user.setLinkColor(details.get("link_color")); user.setBackgroundColor(details.get("background_color")); user.setProtectedTweets(Boolean.parseBoolean(details.get("protected_tweets"))); } ValueNode child = nf.pojoNode(user); root.set("user", child); try { CommandsHelp.submit(map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"), LOGGER); } catch (JsonGenerationException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (JsonMappingException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (IOException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } dbConn.commit(); } catch (PSQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (SQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); //Logger.log(Level.SEVERE, e.getMessage(), e); } finally { PostgresConnection.disconnect(set, proc, dbConn, null); } }
From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonProfessionalRegimesFromGiaf.java
@Override public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger) throws Exception { List<Modification> modifications = new ArrayList<>(); PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance(); PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery()); ResultSet result = preparedStatement.executeQuery(); int count = 0; int news = 0; int notImported = 0; int dontExist = 0; Set<Person> importedButInvalid = new HashSet<Person>(); while (result.next()) { count++;//from w w w.j av a 2 s .c o m String numberString = result.getString("emp_num"); Person person = metadata.getPerson(numberString, logger); if (person == null) { logger.debug("Invalid person with number: " + numberString); dontExist++; continue; } PersonProfessionalData personProfessionalData = person.getPersonProfessionalData(); if (personProfessionalData == null) { logger.debug("Empty personProfessionalData: " + numberString); dontExist++; continue; } final GiafProfessionalData giafProfessionalData = personProfessionalData .getGiafProfessionalDataByGiafPersonIdentification(numberString); if (giafProfessionalData == null) { logger.debug("Empty giafProfessionalData: " + numberString); dontExist++; continue; } final String professionalRegimeGiafId = result.getString("emp_regime"); final ProfessionalRegime professionalRegime = metadata.regime(professionalRegimeGiafId); if (professionalRegime == null) { logger.debug("Empty regime: " + professionalRegimeGiafId + " person number" + numberString); importedButInvalid.add(person); } String beginDateString = result.getString("emp_regime_dt"); final LocalDate beginDate = StringUtils.isEmpty(beginDateString) ? null : new LocalDate(Timestamp.valueOf(beginDateString)); if (beginDate == null) { logger.debug( "Empty beginDate. Person number: " + numberString + " Regime: " + professionalRegimeGiafId); importedButInvalid.add(person); } String endDateString = result.getString("emp_regime_dt_fim"); final LocalDate endDate = StringUtils.isEmpty(endDateString) ? null : new LocalDate(Timestamp.valueOf(endDateString)); if (endDate != null) { if (beginDate != null && beginDate.isAfter(endDate)) { logger.debug("BeginDate after EndDate. Person number: " + numberString + " begin: " + beginDate + " end:" + endDate); importedButInvalid.add(person); } } // ,a.data_criacao,a.data_alteracao String creationDateString = result.getString("data_criacao"); if (StringUtils.isEmpty(creationDateString)) { logger.debug("Empty creationDate. Person number: " + numberString + " Regime: " + professionalRegimeGiafId); notImported++; continue; } final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString)); String modifiedDateString = result.getString("data_alteracao"); final DateTime modifiedDate = StringUtils.isEmpty(modifiedDateString) ? null : new DateTime(Timestamp.valueOf(modifiedDateString)); if (!hasPersonProfessionalRegime(giafProfessionalData, beginDate, endDate, professionalRegime, professionalRegimeGiafId, creationDate, modifiedDate)) { modifications.add(new Modification() { @Override public void execute() { new PersonProfessionalRegime(giafProfessionalData, beginDate, endDate, professionalRegime, professionalRegimeGiafId, creationDate, modifiedDate); } }); news++; } } result.close(); preparedStatement.close(); int deleted = 0; int totalInFenix = 0; int repeted = 0; for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) { for (final PersonProfessionalRegime personProfessionalRegime : giafProfessionalData .getPersonProfessionalRegimesSet()) { if (personProfessionalRegime.getAnulationDate() == null) { int countThisPersonProfessionalRegimeOnGiaf = countThisPersonProfessionalRegimeOnGiaf( oracleConnection, personProfessionalRegime, logger); if (countThisPersonProfessionalRegimeOnGiaf == 0) { modifications.add(new Modification() { @Override public void execute() { personProfessionalRegime.setAnulationDate(new DateTime()); } }); deleted++; } else { totalInFenix++; if (countThisPersonProfessionalRegimeOnGiaf > 1) { repeted += countThisPersonProfessionalRegimeOnGiaf - 1; } } } } } oracleConnection.closeConnection(); log.println("-- Professional regimes --"); log.println("Total GIAF: " + count); log.println("New: " + news); log.println("Deleted: " + deleted); log.println("Not imported: " + notImported); log.println("Imported with errors: " + importedButInvalid.size()); log.println("Repeted: " + repeted); log.println("Invalid persons: " + dontExist); log.println("Total Fnix: " + totalInFenix); log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size())); log.println("Missing in Fnix: " + (count - totalInFenix)); return modifications; }
From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonAbsencesFromGiaf.java
@Override public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger) throws Exception { List<Modification> modifications = new ArrayList<>(); PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance(); PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery(metadata)); ResultSet result = preparedStatement.executeQuery(); int count = 0; int news = 0; int notImported = 0; int dontExist = 0; Set<Person> importedButInvalid = new HashSet<Person>(); while (result.next()) { count++;/*from w w w . j av a2s .co m*/ String numberString = result.getString("emp_num"); Person person = metadata.getPerson(numberString, logger); if (person == null) { logger.debug("Invalid person with number: " + numberString); dontExist++; continue; } PersonProfessionalData personProfessionalData = person.getPersonProfessionalData(); if (personProfessionalData == null) { logger.debug("Empty personProfessionalData: " + numberString); dontExist++; continue; } final GiafProfessionalData giafProfessionalData = personProfessionalData .getGiafProfessionalDataByGiafPersonIdentification(numberString); if (giafProfessionalData == null) { logger.debug("Empty giafProfessionalData: " + numberString); dontExist++; continue; } final String absenceGiafId = result.getString("flt_tip"); final Absence absence = metadata.absence(absenceGiafId); if (absence == null) { logger.debug("Empty absence: " + absenceGiafId + " for person number: " + numberString); importedButInvalid.add(person); } String beginDateString = result.getString("FLT_DT_INIC"); final LocalDate beginDate = StringUtils.isEmpty(beginDateString) ? null : new LocalDate(Timestamp.valueOf(beginDateString)); if (beginDate == null) { logger.debug("Empty beginDate. Person number: " + numberString + " Absence: " + absenceGiafId); importedButInvalid.add(person); } String endDateString = result.getString("FLT_DT_FIM"); final LocalDate endDate = StringUtils.isEmpty(endDateString) ? null : new LocalDate(Timestamp.valueOf(endDateString)); if (beginDate != null && endDate != null) { if (beginDate.isAfter(endDate)) { logger.debug("BeginDate after endDate. Person number: " + numberString + " begin: " + beginDate + " end: " + endDate); importedButInvalid.add(person); } } String creationDateString = result.getString("data_criacao"); if (StringUtils.isEmpty(creationDateString)) { logger.debug("Empty creationDate. Person number: " + numberString + " Absence: " + absenceGiafId); notImported++; continue; } final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString)); String modifiedDateString = result.getString("data_alteracao"); final DateTime modifiedDate = StringUtils.isEmpty(modifiedDateString) ? null : new DateTime(Timestamp.valueOf(modifiedDateString)); if (!hasPersonAbsence(giafProfessionalData, beginDate, endDate, absence, absenceGiafId, creationDate, modifiedDate)) { modifications.add(new Modification() { @Override public void execute() { new PersonAbsence(giafProfessionalData, beginDate, endDate, absence, absenceGiafId, creationDate, modifiedDate); } }); news++; } } result.close(); preparedStatement.close(); int deleted = 0; int totalInFenix = 0; int repeted = 0; for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) { for (PersonProfessionalExemption personProfessionalExemption : giafProfessionalData .getPersonProfessionalExemptionsSet()) { if (personProfessionalExemption instanceof PersonAbsence && personProfessionalExemption.getAnulationDate() == null) { PersonAbsence personAbsence = (PersonAbsence) personProfessionalExemption; int countThisPersonAbsenceOnGiaf = countThisPersonAbsenceOnGiaf(oracleConnection, personAbsence, logger); if (countThisPersonAbsenceOnGiaf == 0) { personAbsence.setAnulationDate(new DateTime()); deleted++; } else { totalInFenix++; if (countThisPersonAbsenceOnGiaf > 1) { repeted += countThisPersonAbsenceOnGiaf - 1; } } } } } oracleConnection.closeConnection(); log.println("-- Absences --"); log.println("Total GIAF: " + count); log.println("New: " + news); log.println("Deleted: " + deleted); log.println("Not imported: " + notImported); log.println("Imported with errors: " + importedButInvalid.size()); log.println("Repeted: " + repeted); log.println("Invalid persons: " + dontExist); log.println("Total Fnix: " + totalInFenix); log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size())); log.println("Missing in Fnix: " + (count - totalInFenix)); return modifications; }
From source file:com.br.ifpb.servlet.UploadImagemPerfil.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w . java2s. c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Usuario usuario = ((Usuario) request.getSession().getAttribute("usuario")); if (usuario == null) { response.sendRedirect(""); } else { boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = null; try { items = (List<FileItem>) upload.parseRequest(request); } catch (FileUploadException ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } FileItem item = items.get(0); if (item != null) { String nome_arquivo = String.valueOf(new Date().getTime()) + item.getName(); String caminho = getServletContext().getRealPath("/imagens") + "\\" + usuario.getId() + "\\"; File file = new File(caminho); if (!file.exists()) { file.mkdirs(); } File uploadedFile = new File(caminho + nome_arquivo); try { item.write(uploadedFile); } catch (Exception ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } GerenciarUsuario gerenciarUsuario = new GerenciarUsuario(); try { gerenciarUsuario.atualizarFotoPerfil("imagens" + "/" + usuario.getId() + "/" + nome_arquivo, usuario.getId()); } catch (PersistenciaException ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } GerenciarFotos gerenciarFotos = new GerenciarFotos(); try { gerenciarFotos.publicarFoto("imagens" + "/" + usuario.getId() + "/" + nome_arquivo, Timestamp.valueOf(LocalDateTime.now()), usuario); } catch (PersistenciaException ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } try { usuario = gerenciarUsuario.getUsuario(usuario.getId()); } catch (PersistenciaException ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } request.getSession().setAttribute("usuario", usuario); response.sendRedirect("configuracao"); } else { } } } }