Commit bd2660d8 by Jan Hrabal

wip - attachments

parent dbda556e
......@@ -226,4 +226,24 @@ CREATE TABLE LEGAL_DOCUMENT (
CREATE INDEX LEGAL_DOCUMENT_IDX ON LEGAL_DOCUMENT(CODE, LOCALE);
-- ATTACHMENTS
CREATE TABLE ATTACHMENT (
ID INT8 NOT NULL,
UNIT_ID INT8 NOT NULL,
OBJECT_TYPE VARCHAR(128),
OBJECT_ID INT8,
NAME VARCHAR(256),
MIME_TYPE VARCHAR(100),
SIZE NUMERIC(19,0),
FILENAME VARCHAR(2000),
UPLOADED DATE,
CONSTRAINT PK_ATTACHMENT PRIMARY KEY(ID),
CONSTRAINT FK_ATTACHMENT_UNIT FOREIGN KEY (UNIT_ID) REFERENCES UNIT(ID)
);
CREATE INDEX ATTACHMENT_IDX ON ATTACHMENT(UNIT_ID, OBJECT_TYPE, OBJECT_ID);
-- TODO
\ No newline at end of file
package com.jh.boot.attachment;
import java.io.InputStream;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
public abstract class AbstractHibernateAttachmentService implements AttachmentService {
private AttachmentRepository repository;
@Override
public Attachment saveAttachment(Attachment attachment, InputStream content) {
// TODO Auto-generated method stub
return null;
}
@Override
public Attachment saveAttachment(Attachment attachment) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Attachment> fetchAttachments(String userId, String objectType, Long objectId) {
// TODO Auto-generated method stub
return null;
}
@Override
public Attachment fetchAttachmentInfo(Long attachmentId) {
// TODO Auto-generated method stub
return null;
}
@Override
public void deleteAttachment(Long attachmentId) {
// TODO Auto-generated method stub
}
@Autowired(required = false)
public void setRepository(AttachmentRepository repository) {
this.repository = repository;
}
}
package com.jh.boot.attachment;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import com.jh.boot.jpa.AbstractIdEntity;
/**
* The Class Attachment.
*/
@Entity
@Table(name = "ATTACHMENT")
public class Attachment extends AbstractIdEntity {
/** The unit id. */
@Column(name = "UNIT_ID")
private Long unitId;
/** The object type. */
@Column(name = "OBJECT_TYPE")
private String objectType;
/** The object id. */
@Column(name = "OBJECT_ID")
private Long objectId;
/** The name. */
private String name;
/** The mime type. */
@Column(name = "MIME_TYPE")
private String mimeType;
/** The size. */
@Column(name = "SIZE")
private Long size;
/** The filename. */
@Column(name = "FILENAME")
private String filename;
/** The uploaded. */
@Column(name = "UPLOADED")
private Date uploaded;
/**
* Gets the unit id.
*
* @return the unit id
*/
public Long getUnitId() {
return unitId;
}
/**
* Sets the unit id.
*
* @param unitId the new unit id
*/
public void setUnitId(Long unitId) {
this.unitId = unitId;
}
/**
* Gets the object type.
*
* @return the object type
*/
public String getObjectType() {
return objectType;
}
/**
* Sets the object type.
*
* @param objectType the new object type
*/
public void setObjectType(String objectType) {
this.objectType = objectType;
}
/**
* Gets the object id.
*
* @return the object id
*/
public Long getObjectId() {
return objectId;
}
/**
* Sets the object id.
*
* @param objectId the new object id
*/
public void setObjectId(Long objectId) {
this.objectId = objectId;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the mime type.
*
* @return the mime type
*/
public String getMimeType() {
return mimeType;
}
/**
* Sets the mime type.
*
* @param mimeType the new mime type
*/
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
/**
* Gets the size.
*
* @return the size
*/
public Long getSize() {
return size;
}
/**
* Sets the size.
*
* @param size the new size
*/
public void setSize(Long size) {
this.size = size;
}
/**
* Gets the filename.
*
* @return the filename
*/
public String getFilename() {
return filename;
}
/**
* Sets the filename.
*
* @param filename the new filename
*/
public void setFilename(String filename) {
this.filename = filename;
}
/**
* Gets the uploaded.
*
* @return the uploaded
*/
public Date getUploaded() {
return uploaded;
}
/**
* Sets the uploaded.
*
* @param uploaded the new uploaded
*/
public void setUploaded(Date uploaded) {
this.uploaded = uploaded;
}
}
package com.jh.boot.attachment;
import java.util.Collections;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.jh.boot.jpa.AbstractHibernateRepository;
import com.jh.boot.web.list.PagingInfo;
/**
* The Class AttachmentRepository.
*/
@Repository
public class AttachmentRepository extends AbstractHibernateRepository {
/**
* Find for unit id and object.
*
* @param unitId the unit id
* @param objectType the object type
* @param objectId the object id
* @param paging the paging
* @return the page
*/
public List<Attachment> findForUnitIdAndObject(Long unitId, String objectType, Long objectId, PagingInfo paging) {
// Criteria c = criteria(Attachment.class);
// c.add(Restrictions.eq("unitId", unitId));
// c.add(Restrictions.eq("objectType", objectType));
// c.add(Restrictions.eq("objectId", objectId));
// c.addOrder(Order.desc("uploaded"));
// c.addOrder(Order.desc("name"));
// return pagedResult(c, paging);
return Collections.emptyList();
}
/**
* Find for unit id and object.
*
* @param unitId the unit id
* @param objectType the object type
* @param objectId the object id
* @return the list
*/
public List<Attachment> findForUnitIdAndObject(Long unitId, String objectType, Long objectId) {
return Collections.emptyList();
}
/**
* Find for unit id and id.
*
* @param unitId the unit id
* @param attachmentId the attachment id
* @return the attachment
*/
public Attachment findForUnitIdAndId(Long unitId, Long attachmentId) {
// Criteria c = criteria(Attachment.class);
//
// c.add(Restrictions.eq("unitId", unitId));
// c.add(Restrictions.idEq(attachmentId));
//
// return (Attachment) c.uniqueResult();
return null;
}
/**
* Rename.
*
* @param unitId the unit id
* @param objectType the object type
* @param objectId the object id
* @param attachmentId the attachment id
* @param name the name
*/
public void rename(Long unitId, String objectType, Long objectId, Long attachmentId, String name) {
Attachment a = findForUnitIdAndId(unitId, attachmentId);
a.setName(name);
}
}
package com.jh.boot.attachment;
import java.io.InputStream;
import java.util.List;
public interface AttachmentService {
Attachment saveAttachment(Attachment attachment, InputStream content);
Attachment saveAttachment(Attachment attachment);
List<Attachment> fetchAttachments(String userId, String objectType, Long objectId);
Attachment fetchAttachmentInfo(Long attachmentId);
InputStream fetchAttachmentBody(Long attachmentId);
void deleteAttachment(Long attachmentId);
}
package com.jh.boot.attachment.api;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jh.boot.attachment.Attachment;
import com.jh.boot.attachment.AttachmentService;
@Controller
@ConditionalOnBean(AttachmentService.class)
public class AttachmentApiController {
@Autowired
private AttachmentService service;
@GetMapping("/attachments/{userId}/{objectType}/{objectId}")
public @ResponseBody List<Attachment> listAttachments(@PathVariable("userId") String userId, @PathVariable("objectType") String objectType, @PathVariable("objectId") Long objectId) {
return service.fetchAttachments(userId, objectType, objectId);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment