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:org.ovirt.engine.sdk.decorators.VMWatchDogs.java

/**
 * Fetches VMWatchDog object by id./*w w  w.jav  a2s.  co m*/
 *
 * @return
 *     {@link VMWatchDog }
 *
 * @throws ClientProtocolException
 *             Signals that HTTP/S protocol error has occurred.
 * @throws ServerException
 *             Signals that an oVirt api error has occurred.
 * @throws IOException
 *             Signals that an I/O exception of some sort has occurred.
 */
@Override
public VMWatchDog get(UUID id) throws ClientProtocolException, ServerException, IOException {
    String url = this.parent.getHref() + SLASH + getName() + SLASH + id.toString();
    return getProxy().get(url, org.ovirt.engine.sdk.entities.WatchDog.class, VMWatchDog.class);
}

From source file:com.mycom.products.mywebsite.backend.util.UploadHandler.java

@Override
@ResponseBody/*from  w ww.java  2  s. c o  m*/
@RequestMapping(method = RequestMethod.POST)
protected final void doPost(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    ServletFileUpload uploadHandler = new ServletFileUpload(new DiskFileItemFactory());
    PrintWriter writer = response.getWriter();
    // checks if the request actually contains upload file
    if (!ServletFileUpload.isMultipartContent(request)) {
        // if not, we stop here
        writer.println("Error: Form must has enctype=multipart/form-data.");
        writer.flush();
        return;
    }
    JSONObject json = new JSONObject();
    SimpleDateFormat fmtYMD = new SimpleDateFormat("/" + "yyyyMMdd");
    Date today = new Date();
    String uploadPath = EntryPoint.getUploadPath() + "/";

    try {
        List<FileItem> items = uploadHandler.parseRequest(request);
        if (items != null && items.size() > 0) {
            String saveDir = "", fileCategory = "";
            for (FileItem item : items) {
                if (item.isFormField()) {
                    fileCategory = item.getString();
                }
            }
            saveDir = fileCategory + fmtYMD.format(today);
            // creates the directory if it does not exist
            File uploadDir = new File(uploadPath + saveDir);
            if (!uploadDir.exists()) {
                uploadDir.mkdirs();
            }
            List<HashMap<String, String>> uploadFiles = new ArrayList<>();
            for (FileItem item : items) {
                // processes only fields that are not form fields
                if (!item.isFormField()) {
                    if (saveDir.length() == 0) {
                        json.put("messageCode", "V1001");
                        json.put("messageParams", "File upload type");
                        json.put("status", HttpStatus.BAD_REQUEST);
                        response.setContentType("application/json");
                        writer.write(json.toString());
                        writer.flush();
                    }
                    String originalFileName = "", saveFileName = "", format = "", fileSize = "";
                    // set the default format to png when it is profileImage
                    if (fileCategory.equals("profilePicture")) {
                        format = ".png";
                    }
                    // can't predict fileName and format would be included.
                    // For instance, blob won't be.
                    try {
                        originalFileName = item.getName().substring(0, item.getName().lastIndexOf("."));
                    } catch (Exception e) {
                        // Nothing to do. Skip
                    }
                    try {
                        format = item.getName().substring(item.getName().lastIndexOf("."),
                                item.getName().length());
                    } catch (Exception e) {
                        // Nothing to do. Skip
                    }

                    fileSize = getReadableFileSize(item.getSize());
                    UUID uuid = UUID.randomUUID();
                    saveFileName = new File(uuid.toString() + format).getName();
                    String filePath = uploadPath + saveDir + "/" + saveFileName;
                    if (fileCategory.equals("profilePicture")) {
                        saveProfileImage(item, filePath);
                    }
                    // Time to save in DB
                    LoggedUserBean loginUser;
                    Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
                    if (principal instanceof LoggedUserBean) {
                        loginUser = (LoggedUserBean) principal;
                    } else {
                        throw new SecurityException("Unauthorize File Upload process was attempted.");
                    }
                    StaticContentBean content = new StaticContentBean();
                    content.setFileName(originalFileName + format);
                    content.setFilePath(filePath);
                    content.setFileSize(fileSize);
                    content.setFileType(FileType.valueOf(getFileType(format)));
                    long lastInsertedId = contentService.insert(content, loginUser.getId());
                    // else .... other file types go here

                    HashMap<String, String> fileItem = new HashMap<>();
                    fileItem.put("contentId", "" + lastInsertedId);
                    uploadFiles.add(fileItem);

                }
            }
            json.put("uploadFiles", uploadFiles);
            json.put("status", HttpStatus.OK);
            response.setContentType("application/json");
            writer.write(json.toString());
            writer.flush();
        }
    } catch (FileUploadException e) {
        throw new RuntimeException("File upload Error !", e);
    } catch (Exception e) {
        throw new RuntimeException("File upload Error !", e);
    } finally {
        writer.close();
    }
}

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

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

    if (genContext == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), "expandBody", 1,
                "genContext");
    }/*from w w w .  j av a  2  s  .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 secUserId = ((ICFBamSecUserObj) genDef).getRequiredSecUserId();
        if (secUserId == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), "expandBody", 0,
                    "Value");
        }
        ret = secUserId.toString();
    } else {
        throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), "expandBody",
                "genContext.getGenDef()", genDef, "ICFBamSecUserObj");
    }

    return (ret);
}

From source file:com.feedzai.fos.impl.weka.config.WekaModelConfig.java

/**
 * Sets the ID of the model./*w  w w  . jav  a  2  s.com*/
 *
 * @param id the ID
 */
public void setId(UUID id) {
    this.dirty = true;
    this.id = id;

    this.modelConfig.setProperty(ID, id.toString());
}

From source file:org.ovirt.engine.sdk.decorators.DataCenterClusterNetworks.java

/**
 * Fetches DataCenterClusterNetwork object by id.
 *
 * @return/*from www.  j  a  v  a2 s.  c  o  m*/
 *     {@link DataCenterClusterNetwork }
 *
 * @throws ClientProtocolException
 *             Signals that HTTP/S protocol error has occurred.
 * @throws ServerException
 *             Signals that an oVirt api error has occurred.
 * @throws IOException
 *             Signals that an I/O exception of some sort has occurred.
 */
@Override
public DataCenterClusterNetwork get(UUID id) throws ClientProtocolException, ServerException, IOException {
    String url = this.parent.getHref() + SLASH + getName() + SLASH + id.toString();
    return getProxy().get(url, org.ovirt.engine.sdk.entities.Network.class, DataCenterClusterNetwork.class);
}

From source file:org.ovirt.engine.sdk.decorators.DataCenterStorageDomains.java

/**
 * Fetches DataCenterStorageDomain object by id.
 *
 * @return//from w  w w.j av a2  s  .  co  m
 *     {@link DataCenterStorageDomain }
 *
 * @throws ClientProtocolException
 *             Signals that HTTP/S protocol error has occurred.
 * @throws ServerException
 *             Signals that an oVirt api error has occurred.
 * @throws IOException
 *             Signals that an I/O exception of some sort has occurred.
 */
@Override
public DataCenterStorageDomain get(UUID id) throws ClientProtocolException, ServerException, IOException {
    String url = this.parent.getHref() + SLASH + getName() + SLASH + id.toString();
    return getProxy().get(url, org.ovirt.engine.sdk.entities.StorageDomain.class,
            DataCenterStorageDomain.class);
}

From source file:org.ovirt.engine.sdk.decorators.VMCdRoms.java

/**
 * Fetches VMCdRom object by id.//from  ww  w .j a  v  a 2  s.  c  om
 *
 * @return
 *     {@link VMCdRom }
 *
 * @throws ClientProtocolException
 *             Signals that HTTP/S protocol error has occurred.
 * @throws ServerException
 *             Signals that an oVirt api error has occurred.
 * @throws IOException
 *             Signals that an I/O exception of some sort has occurred.
 */
@Override
public VMCdRom get(UUID id) throws ClientProtocolException, ServerException, IOException {
    String url = this.parent.getHref() + SLASH + getName() + SLASH + id.toString();
    return getProxy().get(url, org.ovirt.engine.sdk.entities.CdRom.class, VMCdRom.class);
}

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

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

    if (genContext == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), "expandBody", 1,
                "genContext");
    }/*from  w ww  . j ava 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 ICFBamSecDeviceObj) {
        UUID secUserId = ((ICFBamSecDeviceObj) genDef).getRequiredSecUserId();
        if (secUserId == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), "expandBody", 0,
                    "Value");
        }
        ret = secUserId.toString();
    } else {
        throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), "expandBody",
                "genContext.getGenDef()", genDef, "ICFBamSecDeviceObj");
    }

    return (ret);
}

From source file:org.ovirt.engine.sdk.decorators.ClusterCpuProfiles.java

/**
 * Fetches ClusterCpuProfile object by id.
 *
 * @return/* ww  w . j  a  v  a  2  s  . c o  m*/
 *     {@link ClusterCpuProfile }
 *
 * @throws ClientProtocolException
 *             Signals that HTTP/S protocol error has occurred.
 * @throws ServerException
 *             Signals that an oVirt api error has occurred.
 * @throws IOException
 *             Signals that an I/O exception of some sort has occurred.
 */
@Override
public ClusterCpuProfile get(UUID id) throws ClientProtocolException, ServerException, IOException {
    String url = this.parent.getHref() + SLASH + getName() + SLASH + id.toString();
    return getProxy().get(url, org.ovirt.engine.sdk.entities.CpuProfile.class, ClusterCpuProfile.class);
}

From source file:org.ovirt.engine.sdk.decorators.DataCenters.java

/**
 * Fetches DataCenter object by id./*  w  ww  . ja  v  a2 s .c  om*/
 *
 * @return {@link DataCenter }
 *
 * @throws ClientProtocolException
 *             Signals that HTTP/S protocol error has occurred.
 * @throws ServerException
 *             Signals that an oVirt api error has occurred.
 * @throws IOException
 *             Signals that an I/O exception of some sort has occurred.
 */
@Override
public DataCenter get(UUID id) throws ClientProtocolException, ServerException, IOException {
    String url = SLASH + getName() + SLASH + id.toString();
    return getProxy().get(url, org.ovirt.engine.sdk.entities.DataCenter.class, DataCenter.class);
}