Skip to content

Instantly share code, notes, and snippets.

@fieldju
Created November 13, 2012 06:51
Show Gist options
  • Save fieldju/4064373 to your computer and use it in GitHub Desktop.
Save fieldju/4064373 to your computer and use it in GitHub Desktop.
method
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void getBTOConvertAndSaveToForeman(final Integer itemVersionId) {
ItemVersion itemVersion = null;
String sql = "" +
"SELECT " +
"c.createStaffName, " + //1
"p.hed, " + //2
"p.body, " + //3
"c.createDate, " + //4
"c.modifyDate, " + //5
"p.rating1, " + //6
"p.rating2, " + //7
"p.rating3, " + //8
"p.rating4, " + //9
"p.finalRating, " + //10
"c.dontShowBeforeDate, " + //11
"c.hidden, " + //12
"c.published " + //13
"FROM blogsdb2_preview.post AS p " +
"JOIN blogsdb2_preview.content AS c ON ( p.contentId = c.contentId ) " +
"WHERE p.contentId = ";
try {
itemVersion = foremanDao.get(ItemVersion.class, itemVersionId);
} catch (Exception e) {
LOG.error("failed to get ItemVersion", e);
}
if (itemVersion == null)
throw new Error("item version was null");
// get the BTO ReviewId
Integer id = itemVersion.getReviewId();
// if the review has already been imported then use the foreman editorial review
// do not duplicate it
if (processedReviews.containsKey(id)) {
LOG.info("BTO Review: " + id +
" has already been imported assigning it to itemVersion: " +
itemVersionId);
Integer editorialReviewId = processedReviews.get(id);
EditorialReview existingReview =
foremanDao.get(EditorialReview.class, editorialReviewId);
itemVersion.setEditorialReview(existingReview);
return;
}
LOG.info("processing BTO Review: : " + LangUtils.ifNull(id, "NULL REVIEW ID") +
" | itemVersion: " + itemVersionId);
// connect to BTO
Connection c = null;
Statement s = null;
ResultSet result = null;
try {
final Context ctx = new InitialContext();
final DataSource ds = (DataSource) ctx.lookup(blogDbPoolResourceName);
c = ds.getConnection();
s = c.createStatement();
result = s.executeQuery(sql + id);
if (result.next()) {
try {
EditorialReview review = new EditorialReview(itemVersion);
EditorialReviewContent content = review.getContent(Locale.ENGLISH);
content.setAuthorUrsId(LangUtils.ifNull(result.getString(1), "__default.rps.user.id__"));
content.setHeadline( LangUtils.ifNull(result.getString(2), "") );
content.setBody( LangUtils.ifNull(result.getString(3), "") );
review.setCreateDTTM( LangUtils.ifNull(result.getDate(4), null) );
review.setModifyDTTM( LangUtils.ifNull(result.getDate(5), null) );
review.setInstallationAndSetupRating( LangUtils.ifNull(result.getInt(6), 0) );
review.setFeaturesAndSupportRating( LangUtils.ifNull(result.getInt(7), 0) );
review.setUiRating( LangUtils.ifNull(result.getInt(8), 0) );
review.setPerformanceRating( LangUtils.ifNull(result.getInt(9), 0) );
review.setCnetRatingRating( LangUtils.ifNull(result.getInt(10), 0) );
review.setDontPublishBeforeDTTM( LangUtils.ifNull(result.getDate(11), null) );
Boolean hidden = LangUtils.ifNull(result.getBoolean(12), false);
Boolean published = LangUtils.ifNull(result.getBoolean(13), false);
review.setVersion( LangUtils.ifNull(itemVersion.getVersionNumber(), "Not Known") );
if (hidden) {
review.setStatus(publishStatus.HIDDEN);
} else {
if (published) {
review.setStatus(publishStatus.LIVE);
} else {
review.setStatus(publishStatus.PENDING);
}
}
content.setAuthor(getAuthorFromUrsId(content.getAuthorUrsId()));
itemVersion.setEditorialReview(review);
foremanDao.save(review);
processedReviews.put(id, review.getId());
} catch (Exception e) {
LOG.error("Failed to process Review: " +
LangUtils.ifNull(id, "NULL reviewId") + " | itemVersion: " +
LangUtils.ifNull(itemVersionId, "NULL itemVersionId"), e);
}
} else {
LOG.warn("Review not found on BTO for ReviewId: " +
LangUtils.ifNull(id, "NULL reviewId") + " | itemVersion: " +
LangUtils.ifNull(itemVersionId, "NULL itemVersionId"));
}
} catch (Exception e) {
LOG.error("failed to queryBTO", e);
} finally {
try {
if (result != null)
result.close();
} catch (SQLException seql) {
// Do nothing...
}
try {
if (s != null)
s.close();
} catch (SQLException seql) {
// Do nothing...
}
try {
if (c != null)
c.close();
} catch (SQLException seql) {
// Do nothing...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment