Package com.casamind.adware.server.domain

Source Code of com.casamind.adware.server.domain.Resource

package com.casamind.adware.server.domain;

import com.casamind.adware.server.proxy.DatastoreProxy;
import com.casamind.adware.shared.model.ResourceDTO;
import com.casamind.adware.shared.model.ResourceSummaryDTO;

public class Resource extends DatastoreObject {
  private Long productId;
  private String filename;
  private String filesize;
  private String mimeType;
  private String imageURL;
  private String blobKey;

  public Resource() {
  }

  public Resource(Long productId, String filename, String filesize, String mimeType, String imageURL, String blobKey) {
    super();
    this.productId = productId;
    this.filename = filename;
    this.filesize = filesize;
    this.imageURL = imageURL;
  }

  public Long getProductId() {
    return productId;
  }

  public void setProductId(Long productId) {
    this.productId = productId;
  }

  public String getFilename() {
    return filename;
  }

  public void setFilename(String filename) {
    this.filename = filename;
  }

  public String getFilesize() {
    return filesize;
  }

  public void setFilesize(String filesize) {
    this.filesize = filesize;
  }

  public void setMimeType(String mimeType) {
    this.mimeType = mimeType;
  }

  public String getMimeType() {
    return mimeType;
  }

  public String getImageURL() {
    return imageURL;
  }

  public void setImageURL(String imageURL) {
    this.imageURL = imageURL;
  }

  public void setBlobKey(String blobKey) {
    this.blobKey = blobKey;
  }

  public String getBlobKey() {
    return blobKey;
  }

  public static ResourceSummaryDTO toSummaryDTO(Resource resource) {
    return resource == null ? null : new ResourceSummaryDTO(resource.getId(), resource.getProductId(), resource.getFilename(), resource.getImageURL());
  }

  public static ResourceDTO toDTO(Resource entity) {
    if(entity == null)
      return null;
    Product product = DatastoreProxy.getProductById(entity.getProductId());
    if (product != null){
      Publisher publisher = DatastoreProxy.getPublisherById(product.getPublisherId());
      if (publisher != null){
        Company company = DatastoreProxy.getCompanyById(publisher.getCompanyId());
        if (company !=  null){
          return new ResourceDTO(entity.getId(), entity.getUUID(),
              entity.getFilename(), entity.getMimeType(), entity.getFilesize(),
              entity.getImageURL(), entity.getBlobKey(),
              Company.toSummaryDTO(company),
              Publisher.toSummaryDTO(publisher),
              Product.toSummaryDTO(product));
        }
      }
    }
    return null;
  }

  public static Resource toEntity(Resource entity, ResourceDTO dto) {
    if (dto == null) {
      return null;
    }
    if (entity == null) {
      entity = new Resource();
    }
    entity.setProductId(dto.getProduct().getId());
    entity.setFilename(dto.getFilename());
    entity.setImageURL(dto.getImageURL());
    entity.setBlobKey(dto.getBlobKey());
    entity.setFilesize(dto.getFilesize());
    entity.setMimeType(dto.getMimeType());
    return entity;
  }
}
TOP

Related Classes of com.casamind.adware.server.domain.Resource

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.