Java tutorial
package io.starter; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Stack; import io.starter.datamodel.ContentData; import io.starter.model.Content; import io.starter.model.ContentExample; import io.starter.model.ContentRating; import io.starter.model.ContentRatingExample; import io.starter.model.ContentRatingExample.Criteria; import io.starter.model.User; import io.starter.model.UserExample; import io.starter.security.dao.MyBatisConnectionFactory; import io.starter.util.ImageUtils; import io.starter.util.S3FS; import io.starter.util.SystemConstants; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.authz.AuthorizationException; import org.apache.shiro.authz.permission.WildcardPermission; import org.apache.shiro.subject.Subject; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import com.extentech.toolkit.Logger; /** * A junit tester for db interaction with the Content object * * @author nick * */ public class TestContent extends AbstractShiroTest implements SystemConstants { SqlSessionFactory sqlSessionFactory; @Before public void setup() { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); } @Test public void testFixContentUrls() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); String youBroken = "%http://youtu.be/%"; // bad ContentExample example = new ContentExample(); io.starter.model.ContentExample.Criteria criteria = example.createCriteria(); criteria.andUrlLike(youBroken); List<Content> results = session.selectList("io.starter.dao.ContentMapper.selectByExample", example); Iterator its = results.iterator(); while (its.hasNext()) { String url = ((Content) its.next()).getUrl(); Logger.logInfo("Fixed Youtube URL: " + url + " -> " + ContentData.fixContentURLs(url)); } session.close(); } @Test public void testGetContentRatingCount() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); Content content = session.selectOne("io.starter.dao.ContentMapper.selectObjByPrimaryKey", 379); assertEquals((Integer) 1, content.getRatingCount()); assertEquals((Integer) 4, content.getCommentCount()); session.close(); } @Test public void testGetContent() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); Content content = session.selectOne("io.starter.dao.ContentMapper.selectByPrimaryKey", 2); assertEquals("Who's There?", content.getDescription()); session.close(); } /** * test inserting some data * */ @Test public void testInsertAndMarkContentTrashed() { Content content = new Content(); content.setUserId(42); content.setAuthor(42); content.setAuthorDevice(1); content.setCopyright("Copyright 2013. All rights reserved"); content.setDescription("CheezBurger Cat"); content.setLicense("CC"); content.setMimeType("text/plain"); content.setUrl("http://www.hazcheezburger.com"); content.setFlag(FLAG_STAR); content.setPostDate(new java.util.Date(System.currentTimeMillis())); // ContentMapper.insert(content); SqlSession session = sqlSessionFactory.openSession(true); session.insert("io.starter.dao.ContentMapper.insert", content); Integer id = content.getId(); if (id == null) fail("Content insertion returns null ID"); try { Content ccx = session.selectOne("io.starter.dao.ContentMapper.selectObjByPrimaryKey", id); User u = ccx.getUser(); if (u == null) fail("User is null for content object inserted with user_id = 1. Content ID: " + id); String s = ccx.getDescription(); if (s == null) fail("Failed to insert Content ID: " + id); } catch (Exception x) { fail("Exception fetching content from new Content ID: " + id); } // test deletion of that new content // content.setFlag(FLAG_DELETED); session = sqlSessionFactory.openSession(true); session.delete("io.starter.dao.ContentMapper.deleteByPrimaryKey", content); try { Content ccd = session.selectOne("io.starter.dao.ContentMapper.selectByPrimaryKey", id); if (ccd.getFlag() != FLAG_DELETED) fail("Failed to mark deleted newly inserted Content ID: " + id); } catch (Exception x) { // good! } session.close(); } /** * test inserting some data * */ @Test public void testInsertAndDeleteContent() { Content content = new Content(); content.setAuthor(1); content.setAuthorDevice(1); content.setCopyright("Copyright 2013. All rights reserved"); content.setDescription("CheezBurger Cat"); content.setLicense("CC"); content.setFlag(FLAG_STAR); content.setMimeType("text/plain"); content.setUrl("http://www.hazcheezburger.com"); content.setPostDate(new java.util.Date(System.currentTimeMillis())); sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); session.insert("io.starter.dao.ContentMapper.insert", content); Integer id = content.getId(); if (id == null) fail("Content insertion returns null ID"); try { Content ccx = session.selectOne("io.starter.dao.ContentMapper.selectByPrimaryKey", id); String s = ccx.getDescription(); if (s == null) fail("Failed to insert Content ID: " + id); } catch (Exception x) { fail("Exception fetching content from new Content ID: " + id); } // test deletion of that new content Content cxdel = new Content(); cxdel.setId(id); session = sqlSessionFactory.openSession(true); session.delete("io.starter.dao.ContentMapper.deleteByPrimaryKey", cxdel); session.close(); try { Content ccd = session.selectOne("io.starter.dao.ContentMapper.selectByPrimaryKey", id); String s = ccd.getDescription(); if (s != null) fail("Failed to delete inserted Content ID: " + id); } catch (Exception x) { // good! } } /** * * An example of using the selectByExample, note the critera, if you use the * code autofill you will see all sorts of stuff in there you can select by * * @throws Exception */ @Test public void testGetContentsByContent() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); // the 'example' is essentially the descriptino of the data object we // want ContentExample example = new ContentExample(); io.starter.model.ContentExample.Criteria criteria = example.createCriteria(); criteria.andIdEqualTo(1); List<Content> results = session.selectList("io.starter.dao.ContentMapper.selectByExample", example); Content contents = results.get(0); assertEquals("Knock Knock", contents.getDescription()); session.close(); } /** * * An example of using the selectByExample, note the critera, if you use the * code autofill you will see all sorts of stuff in there you can select by * * @throws Exception */ @Test public void testGetContentObjByContent() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); // the 'example' is essentially the descriptino of the data object we // want ContentExample example = new ContentExample(); io.starter.model.ContentExample.Criteria criteria = example.createCriteria(); criteria.andIdEqualTo(1); List<Content> results = session.selectList("io.starter.dao.ContentMapper.selectObjByExample", example); Content contents = results.get(0); assertEquals("Gianni", contents.getUser().getFirstName()); session.close(); } /** * * an example of a complex query * * @throws Exception */ @Test public void testGetSeveralContentsByList() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); ContentRatingExample example = new ContentRatingExample(); // get everything by user id 1, 2, or 3 List<Integer> contentIds = new ArrayList<Integer>(); contentIds.add(1); contentIds.add(2); contentIds.add(3); example.or().andIdIn(contentIds); List<ContentRating> results = session.selectList("io.starter.dao.ContentMapper.selectByExample", example); assertEquals(2, results.size()); session.close(); } /** * Note this is the same query as above, expressed with a critera * * @throws Exception */ @Test public void testGetSeveralContentsBySpan() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); ContentRatingExample example = new ContentRatingExample(); Criteria criteria = example.createCriteria(); criteria.andIdBetween(0, 4); List<ContentRating> results = session.selectList("io.starter.dao.ContentMapper.selectByExample", example); assertEquals(2, results.size()); session.close(); } /** * Ok, ibatis gets more cool here, note the ratings, we are dynamically * setting up objects that subquery on their own. * * @throws Exception */ @Test @Ignore // we don't select ratings objects anymore... revisit someday public void testGetContentObjectWithRatings() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); Content content = session.selectOne("io.starter.dao.ContentMapper.selectObjByPrimaryKey", 1); assertEquals("Knock Knock", content.getDescription()); ArrayList<ContentRating> ratings = content.getRatings(); ContentRating rating = ratings.get(1); assertEquals("Not Very Good!", rating.getReview()); User user = content.getUser(); assertEquals("spaceghost", user.getUsername()); session.close(); } /** * test cpntent ownership ratings * * @throws Exception */ @Test public void testOwnershipPermissions() throws Exception { Content content = new Content(); content.setAuthor(42); content.setUserId(42); content.setAuthorDevice(1); content.setCopyright("Copyright 2014. All rights reserved"); content.setDescription("TEST Starter Content"); content.setLicense("CC"); content.setFlag(FLAG_STAR); content.setMimeType("text/html"); content.setUrl("http://$$PROJECT_DOMAIN$$"); content.setPostDate(new java.util.Date(System.currentTimeMillis())); sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); session.insert("io.starter.dao.ContentMapper.insert", content); session.commit(); Integer id = content.getId(); assertTrue(id != null); Content ccx = session.selectOne("io.starter.dao.ContentMapper.selectObjByPrimaryKey", id); User user = ccx.getUser(); assertTrue(ccx.getUserId() == 42); // assert that contact info is stripped from this assertEquals(null, user.getEmail()); // and that we got the right user assertEquals("test", user.getUsername()); // 1. Build the Subject instance for the test to run: Subject subjectUnderTest = new Subject.Builder(getSecurityManager()).buildSubject(); // 2. Bind the subject to the current thread: setSubject(subjectUnderTest); // see /login.jsp for these form fields String username = "test"; String password = API_CRYPT_KEY; // create a UsernamePasswordToken using the // username and password provided by the user UsernamePasswordToken token = new UsernamePasswordToken(username, password); // get the user (aka subject) associated with this request. Subject subject = SecurityUtils.getSubject(); try { subject.checkPermission("thing:action"); fail("User INCORRECTLY has permission thing:action"); } catch (AuthorizationException x) { // GOOD! } subject.login(token); user.setSubject(subject); ContentData.setContentOwnerPermissions(content, user, session); WildcardPermission owner = new WildcardPermission(SystemConstants.SECURITY_TARGET_TYPE_CONTENT + ":" + SystemConstants.SECURITY_ACL_OWNER + ":" + content.getId()); assert (user.checkAccess(owner)); // test deletion of that new content session = sqlSessionFactory.openSession(true); session.delete("io.starter.dao.ContentMapper.deleteByPrimaryKey", ccx); try { Content ccd = session.selectOne("io.starter.dao.ContentMapper.selectByPrimaryKey", id); String s1 = ccd.getDescription(); if (s1 != null) fail("Failed to delete inserted Content ID: " + id); } catch (Exception x) { // good! } session.close(); } /** * test cpntent ratings! * * @throws Exception */ @Test @Ignore // we don't select ratings objects anymore... revisit someday public void testRatings() throws Exception { Content content = new Content(); content.setAuthor(42); content.setUserId(42); content.setAuthorDevice(1); content.setCopyright("Copyright 2013. All rights reserved"); content.setDescription("TEST Ostrich Pillow"); content.setLicense("CC"); content.setFlag(FLAG_STAR); content.setMimeType("text/html"); content.setUrl("http://www.ostrichpillow.com"); content.setPostDate(new java.util.Date(System.currentTimeMillis())); sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); session.insert("io.starter.dao.ContentMapper.insert", content); Integer id = content.getId(); assertTrue(id != null); // rate the bastard ContentRating rx = new ContentRating(); rx.setContentId(id); rx.setFlag(0); rx.setRaterId(1); rx.setReview("that kinda sucked"); rx.setType(1); rx.setValue((long) 3); session.insert("io.starter.dao.ContentRatingMapper.insert", rx); session.commit(); Content ccx = session.selectOne("io.starter.dao.ContentMapper.selectObjByPrimaryKey", id); String s = ccx.getDescription(); if (s == null) fail("Failed to insert Content ID: " + id); ArrayList<ContentRating> ratings = ccx.getRatings(); ContentRating rating = ratings.get(0); assertEquals("that kinda sucked", rating.getReview()); User user = ccx.getUser(); assertTrue(ccx.getUserId() == 1); assertEquals("john@$$PROJECT_DOMAIN$$", user.getEmail()); // test deletion of that new content session = sqlSessionFactory.openSession(true); session.delete("io.starter.dao.ContentRatingMapper.deleteByPrimaryKey", rx); session.delete("io.starter.dao.ContentMapper.deleteByPrimaryKey", ccx); session.close(); try { Content ccd = session.selectOne("io.starter.dao.ContentMapper.selectByPrimaryKey", id); String s1 = ccd.getDescription(); if (s1 != null) fail("Failed to delete inserted Content ID: " + id); } catch (Exception x) { // good! } session.close(); } /** * test cpntent ratings! * * @throws Exception */ @Test @Ignore // we don't select ratings objects anymore... revisit someday public void testInsertRatingThroughContent() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); SqlSession session = sqlSessionFactory.openSession(true); Content content = session.selectOne("io.starter.dao.ContentMapper.selectObjByPrimaryKey", 1); assertEquals("Knock Knock", content.getDescription()); ArrayList<ContentRating> ratings = content.getRatings(); ContentRating rating = ratings.get(1); assertEquals("Not Very Good!", rating.getReview()); int ratingCount = ratings.size(); // rate the bastard ContentRating rx = new ContentRating(); rx.setContentId(content.getId()); rx.setFlag(0); rx.setRaterId(1); rx.setReview("that kinda sucked"); rx.setType(1); rx.setValue((long) 3); // here is the new call content.insertContentRating(rx); session = sqlSessionFactory.openSession(true); Content ccx = session.selectOne("io.starter.dao.ContentMapper.selectObjByPrimaryKey", 1); assertTrue(ccx.getRatings().size() == (ratingCount + 1)); assertTrue(ccx.getUserId() == 1); User user = ccx.getUser(); assertEquals("spaceghost", user.getUsername()); } /** * * * OUCH updating content objects totally broken. * * @throws Exception */ @Test @Ignore public void setImageNamesForStarterItems() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); final SqlSession session = sqlSessionFactory.openSession(true); ContentExample example = new ContentExample(); io.starter.model.ContentExample.Criteria criteria = example.createCriteria(); example.setOrderByClause("post_date DESC"); example.setDistinct(true); List<Content> results = session.selectList("io.starter.dao.ContentMapper.selectByExample", example); // update for (Content c : results) { String stz = c.getUrl(); if (stz.indexOf(SystemConstants.S3_STARTER_SERVICE) > -1) { stz = stz.substring(stz.lastIndexOf("/") + 1); Logger.logInfo("Found Starter File: " + stz); c.setUrl(stz); try { ContentExample example1 = new ContentExample(); io.starter.model.ContentExample.Criteria criteria1 = example1.createCriteria(); criteria1.andIdEqualTo(c.getId()); example1.setDistinct(true); int rowsUpdated = session.update("io.starter.dao.ContentMapper.Update_By_Example_Where_Clause", example1); } catch (Exception e) { fail(e.toString()); } } } results = session.selectList("io.starter.dao.ContentMapper.selectObjByExample", example); // update for (Content c : results) { String stz = c.getUrl(); if (stz.indexOf(SystemConstants.S3_STARTER_SERVICE) > -1) { fail("Still Legacy Filenames Exist"); } } } /** * convert to new folder structure for image uploads * * @throws Exception */ @Test @Ignore public void testContentImageProcessing() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); final SqlSession session = sqlSessionFactory.openSession(true); ContentExample example = new ContentExample(); io.starter.model.ContentExample.Criteria criteria = example.createCriteria(); example.setOrderByClause("post_date DESC"); example.setDistinct(true); List<Content> results = session.selectList("io.starter.dao.ContentMapper.selectObjByExample", example); final Stack resu = new Stack(); resu.addAll(results); session.close(); final S3FS s3fs = new S3FS(); while (!resu.isEmpty()) { Thread.sleep(3000); Logger.logInfo(resu.size() + " items left"); Thread tp = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub Content c = (Content) resu.pop(); File fin = null; // get image String uploadedFileLocation = c.getUrl(); fin = new File(uploadedFileLocation); uploadedFileLocation = uploadedFileLocation.substring(0, uploadedFileLocation.indexOf(fin.getName())); uploadedFileLocation += "/" + fin.getName(); File fx = new File(uploadedFileLocation); // intercept and process the incoming IMAGE files if (uploadedFileLocation.toLowerCase().endsWith(".png") || uploadedFileLocation.toLowerCase().endsWith(".jpg") || uploadedFileLocation.toLowerCase().endsWith(".gif") || uploadedFileLocation.toLowerCase().endsWith(".jpeg")) { String urlstr = uploadedFileLocation; try { int userId = c.getUserId(); File[] modfiles = ImageUtils.getStarterPics(fx, userId); // upload with nice names for (File modfile : modfiles) { fx = new File(uploadedFileLocation); String fnstart = modfile.getPath() .substring("$$USER_DIR$$starter/server/test/testimages/processed".length()); fnstart = S3_STARTER_MEDIA_FOLDER + fnstart; s3fs.uploadToBucket(S3_STARTER_MEDIA_BUCKET, new DataInputStream(new FileInputStream(modfile)), fnstart); Logger.logInfo("ContentData saveToFile. saved Starter modified image files:" + S3_STARTER_MEDIA_BUCKET + " file: " + fnstart); } } catch (Exception x) { Logger.logErr("TestContent failure: " + x); } } else { // non image content... folderize try { String fnstart = fx.getPath(); String fnend = fx.getName(); fnend = fnend.substring(fnend.indexOf(".")); // file // type fnstart = fnstart.substring(0, fnstart.indexOf(fnend)); if (uploadedFileLocation.startsWith("http:")) { File finx = File.createTempFile("ck-", fnend); fx = ImageUtils.readFromUrl(uploadedFileLocation, finx); } // this is all it takes to create a nice folderizd // structure within the S3 Bucket. fnstart = "/userdata/" + c.getUser().getId() + "/" + fx.getName(); s3fs.uploadToBucket(S3_STARTER_MEDIA_BUCKET, new DataInputStream(new FileInputStream(fx)), fnstart); Logger.logInfo("ContentData saveToFile. saved Starter modified image files:" + S3_STARTER_MEDIA_BUCKET + " file: " + fx.getName()); } catch (Exception e) { // Logger.logErr(e); // pretty normal for non // uploads } } } }); tp.start(); } } /** * Note this is the same query as above, expressed with a critera * * @throws Exception */ @Ignore @Test public void testAvatarImageProcessing() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); final SqlSession session = sqlSessionFactory.openSession(true); UserExample example = new UserExample(); io.starter.model.UserExample.Criteria criteria = example.createCriteria(); criteria.andAvatarImageIsNotNull(); example.setDistinct(true); List<User> results = session.selectList("io.starter.dao.UserMapper.selectByExample", example); final Stack resu = new Stack(); resu.addAll(results); session.close(); final S3FS s3fs = new S3FS(); int semaphore = resu.size(); System.setProperty("semaphore", String.valueOf(semaphore)); while (!resu.isEmpty() || semaphore > 0) { Thread.sleep(3000); String s = System.getProperty("semaphore"); semaphore = Integer.parseInt(s); Logger.logInfo(semaphore + " items left"); if (!resu.isEmpty()) { Thread tp = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub User c = (User) resu.pop(); File fin = null; // get image String uploadedFileLocation = c.getAvatarImage(); if (uploadedFileLocation == null) return; fin = new File(uploadedFileLocation); // uploadedFileLocation = // uploadedFileLocation.substring(0, // uploadedFileLocation.indexOf(fin.getName())); // uploadedFileLocation += "/" + fin.getName(); File fx = new File(SystemConstants.S3_STARTER_SERVICE + S3_STARTER_MEDIA_BUCKET + "/" + uploadedFileLocation); // intercept and process the incoming IMAGE files if (uploadedFileLocation.toLowerCase().endsWith(".png") || uploadedFileLocation.toLowerCase().endsWith(".jpg") || uploadedFileLocation.toLowerCase().endsWith(".gif") || uploadedFileLocation.toLowerCase().endsWith(".jpeg")) { String urlstr = uploadedFileLocation; try { int userId = c.getId(); File[] modfiles = ImageUtils.processExistingStarterPics(fx, userId); // upload with nice names for (File modfile : modfiles) { fx = new File(uploadedFileLocation); String fnstart = modfile.getPath().substring( "$$USER_DIR$$starter/server/test/testimages/processed".length()); fnstart = S3_STARTER_MEDIA_FOLDER + fnstart; s3fs.uploadToBucket(S3_STARTER_MEDIA_BUCKET, new DataInputStream(new FileInputStream(modfile)), fnstart); Logger.logInfo("UserData saveToFile. saved Starter modified image files:" + S3_STARTER_MEDIA_BUCKET + " file: " + fnstart); } String s = System.getProperty("semaphore"); int semaphore = Integer.parseInt(s); semaphore--; System.setProperty("semaphore", String.valueOf(semaphore)); } catch (Exception x) { Logger.logErr("TestContent User Image failure: " + x); } } } }); tp.start(); } } } /** * Note this is the same query as above, expressed with a critera * * @throws Exception */ @Test @Ignore public void testNonImageProcessing() throws Exception { sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory(); final SqlSession session = sqlSessionFactory.openSession(true); ContentExample example = new ContentExample(); io.starter.model.ContentExample.Criteria criteria = example.createCriteria(); example.setOrderByClause("post_date DESC"); example.setDistinct(true); List<Content> results = session.selectList("io.starter.dao.ContentMapper.selectObjByExample", example); final Stack resu = new Stack(); resu.addAll(results); session.close(); final S3FS s3fs = new S3FS(); int semaphore = resu.size(); System.setProperty("semaphore", String.valueOf(semaphore)); while (!resu.isEmpty() || semaphore > 0) { Thread.sleep(3000); String s = System.getProperty("semaphore"); semaphore = Integer.parseInt(s); Logger.logInfo(semaphore + " items left"); if (!resu.isEmpty()) { Thread tp = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub Content c = (Content) resu.pop(); File fin = null; // get image String uploadedFileLocation = c.getUrl(); if (uploadedFileLocation == null) return; fin = new File(uploadedFileLocation); // uploadedFileLocation = // uploadedFileLocation.substring(0, // uploadedFileLocation.indexOf(fin.getName())); // uploadedFileLocation += "/" + fin.getName(); File fx = new File(SystemConstants.S3_STARTER_SERVICE + S3_STARTER_MEDIA_BUCKET + "/" + uploadedFileLocation); // intercept and process the incoming IMAGE files if ((uploadedFileLocation.toLowerCase().endsWith(".mov")) || (uploadedFileLocation.toLowerCase().endsWith(".html")) || (uploadedFileLocation.toLowerCase().endsWith(".m4a"))) { String urlstr = uploadedFileLocation; try { int userId = c.getUserId(); File[] modfiles = ImageUtils.processExistingStarterPics(fx, userId); String fnend = uploadedFileLocation; fnend = fnend.substring(fnend.lastIndexOf(".")); // file // type String fnstart = uploadedFileLocation.substring(0, uploadedFileLocation.lastIndexOf(".")); uploadedFileLocation = SystemConstants.S3_STARTER_MEDIA_FOLDER + "/" + userId + "/" + fnstart + "/" + "Standard" + fnend; // upload with nice names for (File modfile : modfiles) { s3fs.uploadToBucket(S3_STARTER_MEDIA_BUCKET, new DataInputStream(new FileInputStream(modfile)), uploadedFileLocation); Logger.logInfo("ContentData saveToFile. saved Starter modified image files:" + S3_STARTER_MEDIA_BUCKET + " file: " + uploadedFileLocation); } } catch (Exception x) { Logger.logErr("TestContent Content Image failure: " + x); } } String s = System.getProperty("semaphore"); int semaphore = Integer.parseInt(s); semaphore--; System.setProperty("semaphore", String.valueOf(semaphore)); } }); tp.start(); } } } }