@Override public String convertToLibraryNumber( String username, String password, String source, MessageContext context) throws NotAuthorizedException { checkPermissions(username, password, context); Person person = null; if (source.startsWith(CGD) && source.length() == 18) { CardGenerationEntry card = CardGenerationEntry.readCardByCGDIdentifier( source.substring(CGD.length(), source.length() - 2)); if (card != null) { person = card.getPerson(); } } if (source.startsWith(CC)) { person = Person.readByDocumentIdNumberAndIdDocumentType( source.substring(CC.length()), IDDocumentType.IDENTITY_CARD); } if (person != null) { if (person.getLibraryCard() != null && person.getLibraryCard().getCardNumber() != null) { return person.getLibraryCard().getCardNumber(); } return person.getIstUsername(); } return StringUtils.EMPTY; }
public ByteArrayOutputStream getFilledPdf(Person person, StudentCandidacy candidacy) throws IOException, DocumentException { InputStream istream = getClass().getResourceAsStream(SANTANDER_APPLICATION_CARD_PDF_PATH); PdfReader reader = new PdfReader(istream); reader.getAcroForm().remove(PdfName.SIGFLAGS); ByteArrayOutputStream output = new ByteArrayOutputStream(); PdfStamper stamper = new PdfStamper(reader, output); form = stamper.getAcroFields(); setField("StudentIdentification", person.getIstUsername()); setField("Phone", person.getDefaultMobilePhoneNumber()); setField("Email", getMail(person)); setField( "CurrentDate", new DateTime().toString(DateTimeFormat.forPattern("dd/MM/yyyy HH:mm"))); SantanderPhotoEntry photoEntryForPerson = SantanderPhotoEntry.getOrCreatePhotoEntryForPerson( candidacy.getRegistration().getPerson()); if (photoEntryForPerson != null) { setField("Sequence", photoEntryForPerson.getPhotoIdentifier()); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BarcodeImageHandler.writeJPEG( BarcodeFactory.createCode39(photoEntryForPerson.getPhotoIdentifier(), false), baos); Jpeg sequenceBarcodeImg = new Jpeg(baos.toByteArray()); float[] sequenceFieldPositions = form.getFieldPositions( "SequenceBarcode"); // 1-lowerleftX, 2-lly, 3-upperRightX, 4-ury sequenceBarcodeImg.setAbsolutePosition( sequenceFieldPositions[1], sequenceFieldPositions[2]); sequenceBarcodeImg.scalePercent(45); stamper.getOverContent(1).addImage(sequenceBarcodeImg); } catch (OutputException e) { logger.error(e.getMessage(), e); } catch (BarcodeException be) { logger.error(be.getMessage(), be); } Jpeg photo = new Jpeg(photoEntryForPerson.getPhotoAsByteArray()); float[] photoFieldPositions = form.getFieldPositions("Photo"); // 1-lowerleftX, 2-lly, 3-upperRightX, 4-ury photo.setAbsolutePosition(photoFieldPositions[1], photoFieldPositions[2]); photo.scalePercent(95); stamper.getOverContent(1).addImage(photo); } try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BarcodeImageHandler.writeJPEG(BarcodeFactory.createCode128(person.getIstUsername()), baos); Jpeg studentIdBarcodeImg = new Jpeg(baos.toByteArray()); float[] studentIdFieldPositions = form.getFieldPositions( "StudentIdentificationBarcode"); // 1-lowerleftX, 2-lly, 3-upperRightX, 4-ury studentIdBarcodeImg.setAbsolutePosition( studentIdFieldPositions[1], studentIdFieldPositions[2]); studentIdBarcodeImg.scalePercent(45); stamper.getOverContent(1).addImage(studentIdBarcodeImg); } catch (OutputException e) { logger.error(e.getMessage(), e); } catch (BarcodeException be) { logger.error(be.getMessage(), be); } stamper.setFormFlattening(true); stamper.close(); return output; }