Example usage for java.util UUID toString

List of usage examples for java.util UUID toString

Introduction

In this page you can find the example usage for java.util UUID toString.

Prototype

public String toString() 

Source Link

Document

Returns a String object representing this UUID .

Usage

From source file:eu.dasish.annotation.backend.dao.impl.JdbcCachedRepresentationDao.java

@Override
public Number addCachedRepresentation(CachedRepresentationInfo cachedInfo, InputStream streamCached)
        throws NotInDataBaseException, IOException {

    UUID externalIdentifier = Helpers.generateUUID();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("externalId", externalIdentifier.toString());
    params.put("mime_type", cachedInfo.getMimeType());
    params.put("tool", cachedInfo.getTool());
    params.put("type", cachedInfo.getType());
    params.put("blob", IOUtils.toByteArray(streamCached));
    StringBuilder sql = new StringBuilder("INSERT INTO ");
    sql.append(cachedRepresentationTableName).append("(").append(external_id).append(",").append(mime_type)
            .append(",").append(tool).append(",").append(type_).append(",").append(file_)
            .append(" ) VALUES (:externalId, :mime_type,  :tool, :type, :blob)");
    final int affectedRows = this.loggedUpdate(sql.toString(), params);
    return getInternalID(externalIdentifier);
}

From source file:lydichris.smashbracket.persistence.TournamentPersistence.java

public Tournament createTournament(Tournament tournament) {
    UUID uuid = UUID.randomUUID();
    String SQL = "insert into tournaments (uuid, name, start_time, size_limit, location, game, host, format, description, is_bracket_visible) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

    jdbcTemplateObject.update(SQL, uuid.toString(), tournament.getName(), tournament.getStartTime(),
            tournament.getMaxEntrants(), null, tournament.getGame(), tournament.getHostId(),
            tournament.getTournamentType().getValue(), tournament.getDescription(),
            tournament.isMatchesRevealed());

    tournament.setId(uuid.toString());/* www. j a  va 2 s .  co  m*/
    return tournament;
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskMssCF.CFAsteriskMssCFBindSecUserDefaultDevSecUserId.java

public String expandBody(MssCFGenContext genContext) {
    final String S_ProcName = "CFAsteriskMssCFBindSecUserDefaultDevSecUserId.expandBody() ";

    if (genContext == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), "expandBody", 1,
                "genContext");
    }/*from w ww  . j av  a  2  s. c  om*/

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), "expandBody", 1,
                "genContext.getGenDef()");
    }

    String ret;

    if (genDef instanceof ICFAsteriskSecUserObj) {
        UUID defaultDevSecUserId = ((ICFAsteriskSecUserObj) genDef).getOptionalDefaultDevSecUserId();
        if (defaultDevSecUserId == null) {
            ret = null;
        } else {
            ret = defaultDevSecUserId.toString();
        }
    } else {
        throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), "expandBody",
                "genContext.getGenDef()", genDef, "ICFAsteriskSecUserObj");
    }

    return (ret);
}

From source file:io.dyn.net.tcp.stomp.StompServer.java

@Override
protected void configurePipeline(ChannelPipeline pipeline) {
    pipeline.addLast("stompEncoder", new StompMessageEncoder());
    pipeline.addLast("stompDecoder", new StompMessageDecoder());
    pipeline.addLast("handler", new SimpleChannelUpstreamHandler() {
        @Override/*from  w  w w .  j  ava  2s .  c  o  m*/
        public void messageReceived(final ChannelHandlerContext ctx, MessageEvent e) throws Exception {
            log.debug("message received: " + e.getMessage());
            if (null != e.getMessage() && e.getMessage() instanceof StompMessage) {
                StompMessage msg = (StompMessage) e.getMessage();
                if (null != msg.header("session-id")) {
                    msg.session = sessions.getIfPresent(msg.header("session-id"));
                } else {
                    String sid = sessionIds.get(ctx.getChannel());
                    if (null != sid) {
                        msg.session = sessions.getIfPresent(sid);
                    }
                }

                switch (msg.command()) {
                case CONNECT:
                case STOMP:
                    // Each client connection gets a fresh session
                    UUID id = UUID.randomUUID();
                    msg.session = new StompSession(id);
                    sessions.put(id.toString(), msg.session);
                    sessionIds.put(ctx.getChannel(), id.toString());
                    msg.session.on("reply", new Handler<Object>() {
                        @Override
                        public void handle(Object o, Object... args) {
                            ctx.getChannel().write(o);
                        }
                    });
                    event("session", msg.session);

                    String vers = msg.header("accept-version");
                    if (null == vers) {
                        msg.session.version = StompSession.Version.v1_0;
                    } else if (vers.contains("1.1")) {
                        msg.session.version = StompSession.Version.v1_1;
                    } else if (vers.contains("1.0")) {
                        msg.session.version = StompSession.Version.v1_0;
                    } else {
                        ctx.getChannel().write(StompMessages
                                .error("Supported protocol versions include 1.0 1.1", "version", "1.0, 1.1"));
                        return;
                    }
                    // Fire the event
                    event("connect", msg);
                    break;
                case DISCONNECT:
                    // Fire the event
                    event("disconnect", msg);
                    break;
                default:
                    // Fire the event
                    event(msg.command().toString().toLowerCase(), msg);
                }
            }
        }
    });
}

From source file:net.sourceforge.msscodefactory.cfbam.v2_7.CFBamMssCF.CFBamMssCFBindSecUserEMailConfirmationUuid.java

public String expandBody(MssCFGenContext genContext) {
    final String S_ProcName = "CFBamMssCFBindSecUserEMailConfirmationUuid.expandBody() ";

    if (genContext == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), "expandBody", 1,
                "genContext");
    }//  w ww  .  j  a v a  2s  .  co m

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), "expandBody", 1,
                "genContext.getGenDef()");
    }

    String ret;

    if (genDef instanceof ICFBamSecUserObj) {
        UUID eMailConfirmationUuid = ((ICFBamSecUserObj) genDef).getOptionalEMailConfirmationUuid();
        if (eMailConfirmationUuid == null) {
            ret = null;
        } else {
            ret = eMailConfirmationUuid.toString();
        }
    } else {
        throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), "expandBody",
                "genContext.getGenDef()", genDef, "ICFBamSecUserObj");
    }

    return (ret);
}

From source file:org.ohmage.query.impl.CampaignImageQueries.java

public List<String> getCampaignIdsForImageId(UUID imageId) throws DataAccessException {
    try {/* w  w  w  .  j  a v a 2s .  c  o m*/
        return getJdbcTemplate().query(SQL_GET_CAMPAIGN_IDS_FOR_IMAGE, new Object[] { imageId.toString() },
                new SingleColumnRowMapper<String>());
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException(
                "Error executing SQL '" + SQL_GET_CAMPAIGN_IDS_FOR_IMAGE + "' with parameter: " + imageId, e);
    }
}

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_4.CFFreeSwitchMssCF.CFFreeSwitchMssCFBindSecUserDefaultDevSecUserId.java

public String expandBody(MssCFGenContext genContext) {
    final String S_ProcName = "CFFreeSwitchMssCFBindSecUserDefaultDevSecUserId.expandBody() ";

    if (genContext == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), "expandBody", 1,
                "genContext");
    }/*ww  w.j a v  a  2s .c  o m*/

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), "expandBody", 1,
                "genContext.getGenDef()");
    }

    String ret;

    if (genDef instanceof ICFFreeSwitchSecUserObj) {
        UUID defaultDevSecUserId = ((ICFFreeSwitchSecUserObj) genDef).getOptionalDefaultDevSecUserId();
        if (defaultDevSecUserId == null) {
            ret = null;
        } else {
            ret = defaultDevSecUserId.toString();
        }
    } else {
        throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), "expandBody",
                "genContext.getGenDef()", genDef, "ICFFreeSwitchSecUserObj");
    }

    return (ret);
}

From source file:com.mycompany.mytubeaws.UploadServlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//w  w w .j av  a2s.  co  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 {
    String result = "";
    String fileName = null;

    boolean uploaded = false;

    // configures upload settings
    DiskFileItemFactory factory = new DiskFileItemFactory(); // sets memory threshold - beyond which files are stored in disk
    factory.setSizeThreshold(1024 * 1024 * 3); // 3mb
    factory.setRepository(new File(System.getProperty("java.io.tmpdir"))); // sets temporary location to store files

    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setFileSizeMax(1024 * 1024 * 40); // sets maximum size of upload file
    upload.setSizeMax(1024 * 1024 * 50); // sets maximum size of request (include file + form data)

    try {
        List<FileItem> formItems = upload.parseRequest(request); // parses the request's content to extract file data

        if (formItems != null && formItems.size() > 0) // iterates over form's fields
        {
            for (FileItem item : formItems) // processes only fields that are not form fields
            {
                if (!item.isFormField()) {
                    fileName = item.getName();
                    UUID id = UUID.randomUUID();
                    fileName = FilenameUtils.getBaseName(fileName) + "_ID-" + id.toString() + "."
                            + FilenameUtils.getExtension(fileName);

                    File file = File.createTempFile("aws-java-sdk-upload", "");
                    item.write(file); // write form item to file (?)

                    if (file.length() == 0)
                        throw new RuntimeException("No file selected or empty file uploaded.");

                    try {
                        s3.putObject(new PutObjectRequest(bucketName, fileName, file));
                        result += "File uploaded successfully; ";
                        uploaded = true;
                    } catch (AmazonServiceException ase) {
                        System.out.println("Caught an AmazonServiceException, which means your request made it "
                                + "to Amazon S3, but was rejected with an error response for some reason.");
                        System.out.println("Error Message:    " + ase.getMessage());
                        System.out.println("HTTP Status Code: " + ase.getStatusCode());
                        System.out.println("AWS Error Code:   " + ase.getErrorCode());
                        System.out.println("Error Type:       " + ase.getErrorType());
                        System.out.println("Request ID:       " + ase.getRequestId());

                        result += "AmazonServiceException thrown; ";
                    } catch (AmazonClientException ace) {
                        System.out
                                .println("Caught an AmazonClientException, which means the client encountered "
                                        + "a serious internal problem while trying to communicate with S3, "
                                        + "such as not being able to access the network.");
                        System.out.println("Error Message: " + ace.getMessage());

                        result += "AmazonClientException thrown; ";
                    }

                    file.delete();
                }
            }
        }
    } catch (Exception ex) {
        result += "Generic exception: '" + ex.getMessage() + "'; ";
        ex.printStackTrace();
    }

    if (fileName != null && uploaded)
        result += "Generated file ID: " + fileName;

    System.out.println(result);

    request.setAttribute("resultText", result);
    request.getRequestDispatcher("/UploadResult.jsp").forward(request, response);
}

From source file:com.relicum.ipsum.Configuration.PlayerHandler.java

public void load(UUID uuid, String name) throws IOException {

    if (!players.containsKey(uuid)) {

        plugin.getLogger().info("Loading PlayerHandler for " + name + " with uuid " + uuid.toString());

        String folder = uuid.toString().substring(0, 2);

        File file = new File(plugin.getDataFolder(),
                "players" + File.separator + folder + File.separator + uuid.toString() + ".json");

        if (!file.getParentFile().exists()) {

            try {
                if (file.getParentFile().mkdirs()) {
                    plugin.getLogger()/* w ww.  j ava  2 s. c o m*/
                            .info("New folder created for player " + name + " with uuid" + uuid.toString());
                }
            } catch (Exception e) {
                plugin.getLogger()
                        .severe("Unable to create new Folder for player " + name + " " + uuid.toString());
                e.printStackTrace();
            }
        }

        file = null;

        GamerData gamerData = GsonIO.readFromFile(
                Paths.get(plugin.getDataFolder().toString() + File.separator + folder + File.separator,
                        uuid.toString() + ".json"),
                GamerData.class, new GamerData());

    }

}

From source file:com.valygard.aohruthless.utils.inventory.InventoryHandler.java

/**
 * Store the player's inventory in the directory. Doesn't avoid overrides
 * because we are only saving the most recent inventory. This method stores
 * the inventory in memory and on disk for convenience.
 * /*ww w  . j  a v  a 2 s .c  om*/
 * @param p
 */
@SuppressWarnings("unchecked")
public void storeInventory(Player p) {
    ItemStack[] items = p.getInventory().getContents();
    ItemStack[] armor = p.getInventory().getArmorContents();

    UUID uuid = p.getUniqueId();
    String name = p.getName();

    this.items.put(name, items);
    this.armor.put(name, armor);

    JsonConfiguration json = new JsonConfiguration(dir, uuid.toString());
    json.writeString("last-known-username", name).writeString("uuid", uuid.toString());

    JSONArray contents = new JSONArray();
    JSONArray armorContents = new JSONArray();

    contents.addAll(Arrays.asList(items));
    armorContents.addAll(Arrays.asList(armor));

    json.writeArray("items", contents).writeArray("armor", armorContents);

    contents.clear();
    armorContents.clear();

    // And clear the inventory
    InventoryUtils.clearInventory(p);
}