Java Code Examples for com.google.appengine.api.users.UserServiceFactory#getUserService()
The following examples show how to use
com.google.appengine.api.users.UserServiceFactory#getUserService() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GuestbookResource.java From appengine-angular-guestbook-java with Apache License 2.0 | 6 votes |
@POST @Path("/{guestbookName}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public GuestbookResponse signGuestbook( @DefaultValue("default") @PathParam("guestbookName") final String guestbookName, final Map<String, String> postData) { UserService userService = UserServiceFactory.getUserService(); DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService(); Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName); // We set the above parent key on each Greeting entity in order to make the queries strong // consistent. Please Note that as a trade off, we can not write to a single guestbook at a // rate more than 1 write/second. String content = postData.get("content"); if (content != null && content.length() > 0) { Date date = new Date(); Entity greeting = new Entity("Greeting", guestbookKey); greeting.setProperty("user", userService.getCurrentUser()); greeting.setProperty("date", date); greeting.setProperty("content", content); datastoreService.put(greeting); } return new GuestbookResponse(guestbookName, getGreetings(guestbookName), null); }
Example 2
Source File: LoginServlet.java From getting-started-java with Apache License 2.0 | 6 votes |
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { UserService userService = UserServiceFactory.getUserService(); if (userService.isUserLoggedIn()) { // Save the relevant profile info and store it in the session. User user = userService.getCurrentUser(); req.getSession().setAttribute("userEmail", user.getEmail()); req.getSession().setAttribute("userId", user.getUserId()); String destination = (String) req.getSession().getAttribute("loginDestination"); if (destination == null) { destination = "/books"; } logger.log(Level.INFO, "logging destination " + destination); resp.sendRedirect(destination); } else { resp.sendRedirect(userService.createLoginURL("/login")); logger.log(Level.INFO, "logging destination /login"); } }
Example 3
Source File: LogoutFilter.java From getting-started-java with Apache License 2.0 | 6 votes |
@Override public void doFilter(ServletRequest servletReq, ServletResponse servletResp, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) servletReq; HttpServletResponse resp = (HttpServletResponse) servletResp; String path = req.getRequestURI(); chain.doFilter(servletReq, servletResp); UserService userService = UserServiceFactory.getUserService(); if (userService.isUserLoggedIn()) { resp.sendRedirect(userService.createLogoutURL("/logout")); } else if (path.startsWith("/logout")) { resp.sendRedirect("/books"); } }
Example 4
Source File: LoginServlet.java From getting-started-java with Apache License 2.0 | 6 votes |
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { UserService userService = UserServiceFactory.getUserService(); if (userService.isUserLoggedIn()) { // Save the relevant profile info and store it in the session. User user = userService.getCurrentUser(); req.getSession().setAttribute("userEmail", user.getEmail()); req.getSession().setAttribute("userId", user.getUserId()); String destination = (String) req.getSession().getAttribute("loginDestination"); if (destination == null) { destination = "/books"; } resp.sendRedirect(destination); } else { resp.sendRedirect(userService.createLoginURL("/login")); } }
Example 5
Source File: SignGuestbookServlet.java From java-docs-samples with Apache License 2.0 | 6 votes |
@Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { Greeting greeting; UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); // Find out who the user is. String guestbookName = req.getParameter("guestbookName"); String content = req.getParameter("content"); if (user != null) { greeting = new Greeting(guestbookName, content, user.getUserId(), user.getEmail()); } else { greeting = new Greeting(guestbookName, content); } greeting.save(); resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName); }
Example 6
Source File: AdminServiceImpl.java From sc2gears with Apache License 2.0 | 6 votes |
@Override public RpcResult< List< MiscFunctionInfo > > getMiscFunctionInfoList() { LOGGER.fine( "" ); final UserService userService = UserServiceFactory.getUserService(); final User user = userService.getCurrentUser(); if ( user == null ) return RpcResult.createNotLoggedInErrorResult(); if ( !userService.isUserAdmin() ) return RpcResult.createNoPermissionErrorResult(); final List< MiscFunctionInfo > miscFunctionInfoList = new ArrayList< MiscFunctionInfo >( miscFunctionMap.size() ); for ( final Entry< String, DatastoreTask > entry : miscFunctionMap.entrySet() ) miscFunctionInfoList.add( new MiscFunctionInfo( entry.getKey(), entry.getValue().getParamNames() ) ); Collections.sort( miscFunctionInfoList, new Comparator< MiscFunctionInfo >() { @Override public int compare( final MiscFunctionInfo i1, final MiscFunctionInfo i2 ) { return i1.getName().compareTo( i2.getName() ); } } ); return new RpcResult< List< MiscFunctionInfo > >( miscFunctionInfoList ); }
Example 7
Source File: ConsoleOteSetupActionTest.java From nomulus with Apache License 2.0 | 5 votes |
@BeforeEach public void setUp() throws Exception { persistPremiumList("default_sandbox_list", "sandbox,USD 1000"); action.req = request; action.method = Method.GET; action.response = response; action.registrarAccessor = AuthenticatedRegistrarAccessor.createForTesting( ImmutableSetMultimap.of("unused", AuthenticatedRegistrarAccessor.Role.ADMIN)); action.userService = UserServiceFactory.getUserService(); action.xsrfTokenManager = new XsrfTokenManager(new FakeClock(), action.userService); action.authResult = AuthResult.create(AuthLevel.USER, UserAuthInfo.create(user, false)); action.sendEmailUtils = new SendEmailUtils( new InternetAddress("[email protected]"), "UnitTest Registry", ImmutableList.of("[email protected]", "[email protected]"), emailService); action.logoFilename = "logo.png"; action.productName = "Nomulus"; action.clientId = Optional.empty(); action.email = Optional.empty(); action.analyticsConfig = ImmutableMap.of("googleAnalyticsId", "sampleId"); action.optionalPassword = Optional.empty(); action.passwordGenerator = new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz"); }
Example 8
Source File: UserServiceImpl.java From sc2gears with Apache License 2.0 | 5 votes |
@Override public RpcResult< List< String > > saveLabelNames( final String sharedAccount, final List< String > labelNames ) { LOGGER.fine( sharedAccount == null ? "" : "Shared account: " + sharedAccount ); final UserService userService = UserServiceFactory.getUserService(); final User user = userService.getCurrentUser(); if ( user == null ) return RpcResult.createNotLoggedInErrorResult(); PersistenceManager pm = null; try { pm = PMF.get().getPersistenceManager(); final Account account = ServerUtils.getAccount( pm, sharedAccount, user ); if ( account == null ) return RpcResult.createNoPermissionErrorResult(); if ( sharedAccount != null && !account.isPermissionGranted( user, Permission.RENAME_LABELS ) ) return RpcResult.createNoPermissionErrorResult(); // Restore default names for empty strings final List< String > checkedNames = new ArrayList< String >( Consts.DEFAULT_REPLAY_LABEL_LIST.size() ); for ( int i = 0; i < Consts.DEFAULT_REPLAY_LABEL_LIST.size(); i++ ) checkedNames.add( i >= labelNames.size() || Consts.DEFAULT_REPLAY_LABEL_LIST.get( i ).equals( labelNames.get( i ) ) ? "" : ServletApi.trimStringLength( labelNames.get( i ), 500 ) ); account.setLabelNames( checkedNames ); final RpcResult< List< String > > rpcResult = new RpcResult< List< String > >( ServerUtils.getLabelNames( account ) ); rpcResult.setInfoMsg( "Label names saved." ); return rpcResult; } finally { if ( pm != null ) pm.close(); } }
Example 9
Source File: GuestbookServlet.java From appengine-modules-sample-java with Apache License 2.0 | 5 votes |
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { final UserService userService = UserServiceFactory.getUserService(); final User currentUser = userService.getCurrentUser(); if (currentUser != null) { resp.setContentType("text/plain"); resp.getWriter().println("Hello, " + currentUser.getNickname()); } else { resp.sendRedirect(userService.createLoginURL(req.getRequestURI())); } }
Example 10
Source File: UserServiceImpl.java From sc2gears with Apache License 2.0 | 5 votes |
@Override public RpcResult< Void > recalcFileStats( final String sharedAccount ) { LOGGER.fine( sharedAccount == null ? "" : "Shared account: " + sharedAccount ); final UserService userService = UserServiceFactory.getUserService(); final User user = userService.getCurrentUser(); if ( user == null ) return RpcResult.createNotLoggedInErrorResult(); PersistenceManager pm = null; try { pm = PMF.get().getPersistenceManager(); final Key accountKey = ServerUtils.getAccountKey( pm, sharedAccount, user, Permission.VIEW_QUOTA ); if ( accountKey == null ) return RpcResult.createNoPermissionErrorResult(); final Event lastRecalcEvent = ServerUtils.getLastEvent( accountKey, Type.FILE_STATS_RECALC_TRIGGERED ); if ( lastRecalcEvent != null && System.currentTimeMillis() - lastRecalcEvent.getDate().getTime() < 24L*60*60*1000 ) { final int hours = (int) ( ( System.currentTimeMillis() - lastRecalcEvent.getDate().getTime() ) / (1000L*60*60) ); return RpcResult.createErrorResult( "Recalculation can only be requested once per 24 hours" + " (last was " + hours + ( hours == 1 ? " hour ago)!" : " hours ago)!" ) ); } TaskServlet.register_recalcFileStatsTask( accountKey ); pm.makePersistent( new Event( accountKey, Type.FILE_STATS_RECALC_TRIGGERED ) ); } finally { if ( pm != null ) pm.close(); } return RpcResult.createInfoResult( "File stats recalculation has been kicked-off, check back in a short time..." ); }
Example 11
Source File: ListByUserFilter.java From getting-started-java with Apache License 2.0 | 5 votes |
@Override public void doFilter(ServletRequest servletReq, ServletResponse servletResp, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) servletReq; HttpServletResponse resp = (HttpServletResponse) servletResp; UserService userService = UserServiceFactory.getUserService(); if (userService.isUserLoggedIn()) { chain.doFilter(servletReq, servletResp); } else { req.getSession().setAttribute("loginDestination", "/books/mine"); resp.sendRedirect(userService.createLoginURL("/login")); } }
Example 12
Source File: UserServiceImpl.java From sc2gears with Apache License 2.0 | 5 votes |
@Override public RpcResult< String > getAuthorizationKey( final String sharedAccount ) { LOGGER.fine( sharedAccount == null ? "" : "Shared account: " + sharedAccount ); final UserService userService = UserServiceFactory.getUserService(); final User user = userService.getCurrentUser(); if ( user == null ) return RpcResult.createNotLoggedInErrorResult(); PersistenceManager pm = null; try { pm = PMF.get().getPersistenceManager(); final Account account = ServerUtils.getAccount( pm, sharedAccount, user ); if ( account == null ) return RpcResult.createNoPermissionErrorResult(); if ( sharedAccount != null && !account.isPermissionGranted( user, Permission.VIEW_AUTHORIZATION_KEY ) ) return RpcResult.createNoPermissionErrorResult(); return new RpcResult< String >( account.getAuthorizationKey() ); } finally { if ( pm != null ) pm.close(); } }
Example 13
Source File: AdminServiceImpl.java From sc2gears with Apache License 2.0 | 5 votes |
@Override public RpcResult< List< NewAccountSuggestion > > getNewAccountSuggestionList() { LOGGER.fine( "" ); final UserService userService = UserServiceFactory.getUserService(); final User user = userService.getCurrentUser(); if ( user == null ) return RpcResult.createNotLoggedInErrorResult(); if ( !userService.isUserAdmin() ) return RpcResult.createNoPermissionErrorResult(); PersistenceManager pm = null; try { pm = PMF.get().getPersistenceManager(); final List< Visit > visitList = new JQBuilder<>( pm, Visit.class ).filter( "visitorKey==null", null ).desc( "date" ).range( 0, 20 ).get(); final List< NewAccountSuggestion > newAccSuggestionList = new ArrayList< NewAccountSuggestion >( visitList.size() + 1 ); if ( !visitList.isEmpty() ) newAccSuggestionList.add( new NewAccountSuggestion() ); for ( final Visit visit : visitList ) { final NewAccountSuggestion newAccSuggestion = new NewAccountSuggestion(); newAccSuggestion.setGoogleAccount( visit.getUser().getEmail() ); newAccSuggestion.setCountryCode ( visit.getCountryCode() ); newAccSuggestion.setCountryName ( ServerUtils.countryCodeToName( visit.getCountryCode() ) ); newAccSuggestionList.add( newAccSuggestion ); } return new RpcResult< List<NewAccountSuggestion> >( newAccSuggestionList ); } finally { if ( pm != null ) pm.close(); } }
Example 14
Source File: SignGuestbookServlet.java From appengine-java-vm-guestbook-extras with Apache License 2.0 | 5 votes |
@Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); String code = (String) req.getParameter("ccode"); String captcha = (String) req.getSession().getAttribute("captcha"); if (captcha != null && code != null) { if (!captcha.trim().equalsIgnoreCase(code)) { resp.getWriter().println("<html><head><title>error</title></head><body>error in captcha." + "<br/><a href='/guestbook.jsp'>Try again</a>.</body></html>"); return; } } else { resp.getWriter().println("error in captcha"); return; } String guestbookName = req.getParameter("guestbookName"); Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName); String content = req.getParameter("content"); Date date = new Date(); Entity greeting = new Entity("Greeting", guestbookKey); greeting.setProperty("user", user); greeting.setProperty("date", date); content = content.substring(0, Math.min(content.length(), 490)); greeting.setProperty("content", content); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); datastore.put(greeting); resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName); }
Example 15
Source File: FileServlet.java From sc2gears with Apache License 2.0 | 4 votes |
@Override protected void doPost( final HttpServletRequest request, final HttpServletResponse response ) throws ServletException, IOException { if (true) { response.sendError(HttpServletResponse.SC_GONE, "This URL is gone and will not be available anymore!"); return; } final String operation = checkProtVerAndGetOperation( PROTOCOL_VERSION_1, request, response ); if ( operation == null ) return; PersistenceManager pm = null; try { pm = PMF.get().getPersistenceManager(); final String authorizationKey = request.getParameter( PARAM_AUTHORIZATION_KEY ); // AUTHENTICATION FIRST // Either authorization key must be provided or a valid Google account must be authenticated! final Account account; final User user; final String sharedAccount = request.getParameter( PARAM_SHARED_ACCOUNT ); if ( authorizationKey == null || authorizationKey.isEmpty() ) { // Google account authentication final UserService userService = UserServiceFactory.getUserService(); user = userService.getCurrentUser(); if ( user == null ) { LOGGER.warning( "Unauthorized access, not logged in!" ); response.sendError( HttpServletResponse.SC_FORBIDDEN, "Unauthorized access, you are not logged in!" ); return; } account = ServerUtils.getAccount( pm, sharedAccount, user ); if ( account == null ) { LOGGER.warning( "Unauthorized access: Google account: " + user.getEmail() + ( sharedAccount == null ? "" : ", shared account: " + sharedAccount ) ); response.sendError( HttpServletResponse.SC_FORBIDDEN, "Unauthorized access!" ); return; } } else { // Authorization key authentication final List< Account > accountList = new JQBuilder<>( pm, Account.class ).filter( "authorizationKey==p1", "String p1" ).get( authorizationKey ); if ( accountList.isEmpty() ) { LOGGER.warning( "Unauthorized access, invalid Authorization Key: " + authorizationKey ); response.sendError( HttpServletResponse.SC_FORBIDDEN, "Unauthorized access, invalid Authorization Key!" ); return; } account = accountList.get( 0 ); user = null; } // ...Authentication OK switch ( operation ) { case OPERATION_STORE : storeFile( request, response, pm, account, sharedAccount ); break; case OPERATION_DOWNLOAD : serveFile( request, response, pm, account, sharedAccount, user ); break; case OPERATION_BATCH_DOWNLOAD : serveFileBatch( request, response, pm, account, sharedAccount, user ); break; case OPERATION_RETRIEVE_FILE_LIST : serveFileList( request, response, pm, account, sharedAccount ); break; default: LOGGER.warning( "Invalid Operation! (Account: " + account.getUser().getEmail() + ")" ); response.sendError( HttpServletResponse.SC_BAD_REQUEST, "Invalid Operation!" ); return; } } finally { if ( pm != null ) pm.close(); } }
Example 16
Source File: XSRFTokenUtility.java From solutions-mobile-backend-starter-java with Apache License 2.0 | 4 votes |
private static String buildTokenString(String secretKey, String action, String time) { UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); return buildTokenString(secretKey, user.getEmail(), action, time); }
Example 17
Source File: UserServiceImpl.java From sc2gears with Apache License 2.0 | 4 votes |
@Override public RpcResult< EntityListResult< MousePrintInfo > > getMousePrintInfoList( final String sharedAccount, final PageInfo pageInfo, final MousePrintFilters filters ) { final String filtersString = filters.toString(); LOGGER.fine( ( sharedAccount == null ? "" : "Shared account: " + sharedAccount + ", " ) + "pageInfo: {" + pageInfo.toString() + "}" + ( filtersString.isEmpty() ? "" : ", filters: {" + filtersString + "}" ) ); final UserService userService = UserServiceFactory.getUserService(); final User user = userService.getCurrentUser(); if ( user == null ) return RpcResult.createNotLoggedInErrorResult(); if ( pageInfo.getLimit() > MAX_PAGE_SIZE ) { LOGGER.warning( "Too big limit supplied: " + pageInfo.getLimit() ); return RpcResult.createErrorResult( "Too big limit supplied: " + pageInfo.getLimit() ); } PersistenceManager pm = null; try { pm = PMF.get().getPersistenceManager(); final Key accountKey = ServerUtils.getAccountKey( pm, sharedAccount, user, Permission.VIEW_MOUSE_PRINTS ); if ( accountKey == null ) return RpcResult.createNoPermissionErrorResult(); final List< Object > paramsList = new ArrayList< Object >(); final StringBuilder filtersBuilder = new StringBuilder( "ownerk==p1" ); final StringBuilder paramsBuilder = new StringBuilder( "KEY p1" ); paramsList.add( accountKey ); if ( filters.getFromDate() != null ) { paramsList.add( filters.getFromDate() ); filtersBuilder.append( " && end>p" ).append( paramsList.size() ); paramsBuilder.append( ", DATE p" ).append( paramsList.size() ); } if ( filters.getToDate() != null ) { filters.getToDate().setTime( filters.getToDate().getTime() + 24L*60*60*1000 ); // Add one day so replays from this day will be included paramsList.add( filters.getToDate() ); filtersBuilder.append( " && end<p" ).append( paramsList.size() ); paramsBuilder.append( ", DATE p" ).append( paramsList.size() ); } final List< Smpd > mousePrintList = new JQBuilder<>( pm, Smpd.class ).filter( filtersBuilder.toString(), paramsBuilder.toString() ).desc( "end" ).pageInfo( pageInfo ).get( paramsList.toArray() ); final List< MousePrintInfo > mousePrintInfoList = new ArrayList< MousePrintInfo >( mousePrintList.size() ); for ( final Smpd mousePrint : mousePrintList ) { final MousePrintInfo mousePrintInfo = new MousePrintInfo(); mousePrintInfo.setRecordingStart( mousePrint.getStart () ); mousePrintInfo.setRecordingEnd ( mousePrint.getEnd () ); mousePrintInfo.setScreenWidth ( mousePrint.getWidth () ); mousePrintInfo.setScreenHeight ( mousePrint.getHeight() ); mousePrintInfo.setFileSize ( mousePrint.getSize () ); mousePrintInfo.setSamplesCount ( mousePrint.getCount () ); mousePrintInfo.setSha1 ( mousePrint.getSha1 () ); mousePrintInfo.setFileName ( mousePrint.getFname () ); mousePrintInfoList.add( mousePrintInfo ); } return new RpcResult< EntityListResult< MousePrintInfo > >( new EntityListResult< MousePrintInfo >( mousePrintInfoList, JDOCursorHelper.getCursor( mousePrintList ).toWebSafeString() ) ); } finally { if ( pm != null ) pm.close(); } }
Example 18
Source File: UserServiceInfo.java From appengine-angular-guestbook-java with Apache License 2.0 | 4 votes |
public static UserServiceInfo get(String path) { UserService userService = UserServiceFactory.getUserService(); return new UserServiceInfo(userService.getCurrentUser(), userService.createLoginURL(path), userService.createLogoutURL(path)); }
Example 19
Source File: UserServiceImpl.java From sc2gears with Apache License 2.0 | 4 votes |
@Override public RpcResult< SettingsInfo > getSettings( final String sharedAccount ) { LOGGER.fine( sharedAccount == null ? "" : "Shared account: " + sharedAccount ); final UserService userService = UserServiceFactory.getUserService(); final User user = userService.getCurrentUser(); if ( user == null ) return RpcResult.createNotLoggedInErrorResult(); PersistenceManager pm = null; try { pm = PMF.get().getPersistenceManager(); final Account account = ServerUtils.getAccount( pm, sharedAccount, user ); if ( account == null ) return RpcResult.createNoPermissionErrorResult(); if ( sharedAccount != null && !account.isPermissionGranted( user, Permission.VIEW_SETTINGS ) ) return RpcResult.createNoPermissionErrorResult(); final SettingsInfo settingsInfo = new SettingsInfo(); settingsInfo.setGoogleAccount ( account.getUser().getEmail () ); settingsInfo.setContactEmail ( account.getContactEmail () ); settingsInfo.setUserName ( account.getName () ); settingsInfo.setNotificationQuotaLevel( account.getNotificationQuotaLevel() ); settingsInfo.setConvertToRealTime ( account.isConvertToRealTime () ); settingsInfo.setMapImageSize ( account.getMapImageSize () ); settingsInfo.setDisplayWinners ( account.getDisplayWinners () ); settingsInfo.setFavoredPlayerList ( ServerUtils.cloneList( account.getFavoredPlayers() ) ); if ( account.getGrantedUsers() == null ) settingsInfo.setGrantedUsers( new ArrayList< String >() ); else { final List< String > grantedUsers = new ArrayList< String >( account.getGrantedUsers().size() ); for ( final User grantedUser : account.getGrantedUsers() ) grantedUsers.add( grantedUser.getEmail() ); settingsInfo.setGrantedUsers( grantedUsers ); } if ( account.getGrantedPermissions() == null ) settingsInfo.setGrantedPermissions( new ArrayList< Long >() ); else settingsInfo.setGrantedPermissions( ServerUtils.cloneList( account.getGrantedPermissions() ) ); return new RpcResult< SettingsInfo >( settingsInfo ); } finally { if ( pm != null ) pm.close(); } }
Example 20
Source File: UserServiceImpl.java From sc2gears with Apache License 2.0 | 4 votes |
public RpcResult< List< String > > getProfileUrlList( String sharedAccount, String sha1 ) { LOGGER.fine( ( sharedAccount == null ? "" : "Shared account: " + sharedAccount + ", " ) + "sha1: " + sha1 ); final UserService userService = UserServiceFactory.getUserService(); final User user = userService.getCurrentUser(); if ( user == null ) return RpcResult.createNotLoggedInErrorResult(); PersistenceManager pm = null; try { pm = PMF.get().getPersistenceManager(); final Key accountKey = ServerUtils.getAccountKey( pm, sharedAccount, user, Permission.VIEW_REPLAYS ); if ( accountKey == null ) return RpcResult.createNoPermissionErrorResult(); // Check if the specified file is owned by the account final List< Rep > replayList = new JQBuilder<>( pm, Rep.class ).filter( "ownerk==p1 && sha1==p2", "KEY p1, String p2" ).get( accountKey, sha1 ); if ( replayList.isEmpty() ) return RpcResult.createNoPermissionErrorResult(); byte[] content = null; try { content = ServerUtils.getFileContent( replayList.get( 0 ), null ); if ( content == null ) { LOGGER.warning( "File not found!" ); return RpcResult.createErrorResult( "Replay not found!" ); } } catch ( final IOException ie ) { LOGGER.log( Level.SEVERE, "Some error occured getting the file from the Blobstore!", ie ); return RpcResult.createErrorResult( "Internal error accessing the replay!" ); } MpqParser mpqParser; try { mpqParser = new MpqParser( new ByteArrayMpqDataInput( content ) ); } catch ( final InvalidMpqArchiveException imae ) { LOGGER.log( Level.WARNING, "Invalid SC2Replay file!", imae ); return RpcResult.createErrorResult( "Invalid SC2Replay file!" ); } final Replay replay = ReplayFactory.parseReplay( "replayFromBlobstore.SC2Replay", mpqParser, ReplayFactory.GENERAL_INFO_CONTENT ); if ( replay == null ) { LOGGER.info( "Error parsing the replay!" ); return RpcResult.createErrorResult( "Error parsing the replay!" ); } final List< String > profileUrlList = new ArrayList< String >(); for ( final String playerName : replayList.get( 0 ).getPlayers() ) { boolean foundMatch = false; for ( final Player p : replay.details.players ) { if ( p.playerId.name.equals( playerName ) ) { foundMatch = true; profileUrlList.add( p.playerId.getBattleNetProfileUrl( null ) ); break; } } if ( !foundMatch ) profileUrlList.add( "" ); // Add an empty string to keep proper player indices } return new RpcResult< List< String > >( profileUrlList ); } finally { if ( pm != null ) pm.close(); } }