Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jh-boot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jan Hrabal
jh-boot
Commits
bd2660d8
Commit
bd2660d8
authored
Sep 26, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip - attachments
parent
dbda556e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
402 additions
and
0 deletions
+402
-0
init.sql
sql/init.sql
+21
-0
AbstractHibernateAttachmentService.java
...h/boot/attachment/AbstractHibernateAttachmentService.java
+49
-0
Attachment.java
src/main/java/com/jh/boot/attachment/Attachment.java
+195
-0
AttachmentRepository.java
...ain/java/com/jh/boot/attachment/AttachmentRepository.java
+87
-0
AttachmentService.java
src/main/java/com/jh/boot/attachment/AttachmentService.java
+20
-0
AttachmentApiController.java
...a/com/jh/boot/attachment/api/AttachmentApiController.java
+30
-0
No files found.
sql/init.sql
View file @
bd2660d8
...
...
@@ -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
src/main/java/com/jh/boot/attachment/AbstractHibernateAttachmentService.java
0 → 100644
View file @
bd2660d8
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
;
}
}
src/main/java/com/jh/boot/attachment/Attachment.java
0 → 100644
View file @
bd2660d8
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
;
}
}
src/main/java/com/jh/boot/attachment/AttachmentRepository.java
0 → 100644
View file @
bd2660d8
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
);
}
}
src/main/java/com/jh/boot/attachment/AttachmentService.java
0 → 100644
View file @
bd2660d8
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
);
}
src/main/java/com/jh/boot/attachment/api/AttachmentApiController.java
0 → 100644
View file @
bd2660d8
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
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment