mirror of
https://github.com/sismics/docs.git
synced 2025-12-13 01:36:18 +00:00
#300: custom metadata fields: API read
This commit is contained in:
@@ -43,7 +43,7 @@ public class DocumentMetadata implements Serializable {
|
||||
/**
|
||||
* Value.
|
||||
*/
|
||||
@Column(name = "DME_VALUE_C", nullable = false, length = 4000)
|
||||
@Column(name = "DME_VALUE_C", length = 4000)
|
||||
private String value;
|
||||
|
||||
public String getId() {
|
||||
|
||||
@@ -8,7 +8,12 @@ import com.sismics.docs.core.dao.criteria.MetadataCriteria;
|
||||
import com.sismics.docs.core.dao.dto.DocumentMetadataDto;
|
||||
import com.sismics.docs.core.dao.dto.MetadataDto;
|
||||
import com.sismics.docs.core.model.jpa.DocumentMetadata;
|
||||
import com.sismics.docs.core.util.jpa.SortCriteria;
|
||||
import com.sismics.util.JsonUtil;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -144,4 +149,31 @@ public class MetadataUtil {
|
||||
documentMetadata.setValue(value);
|
||||
documentMetadataDao.update(documentMetadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom metadata to a JSON response.
|
||||
*
|
||||
* @param json JSON
|
||||
* @param documentId Document ID
|
||||
*/
|
||||
public static void addMetadata(JsonObjectBuilder json, String documentId) {
|
||||
DocumentMetadataDao documentMetadataDao = new DocumentMetadataDao();
|
||||
MetadataDao metadataDao = new MetadataDao();
|
||||
List<MetadataDto> metadataDtoList = metadataDao.findByCriteria(new MetadataCriteria(), new SortCriteria(1, true));
|
||||
List<DocumentMetadataDto> documentMetadataDtoList = documentMetadataDao.getByDocumentId(documentId);
|
||||
JsonArrayBuilder metadata = Json.createArrayBuilder();
|
||||
for (MetadataDto metadataDto : metadataDtoList) {
|
||||
JsonObjectBuilder meta = Json.createObjectBuilder()
|
||||
.add("id", metadataDto.getId())
|
||||
.add("name", metadataDto.getName())
|
||||
.add("type", metadataDto.getType().name());
|
||||
for (DocumentMetadataDto documentMetadataDto : documentMetadataDtoList) {
|
||||
if (documentMetadataDto.getMetadataId().equals(metadataDto.getId())) {
|
||||
meta.add("value", JsonUtil.nullable(documentMetadataDto.getValue()));
|
||||
}
|
||||
}
|
||||
metadata.add(meta);
|
||||
}
|
||||
json.add("metadata", metadata);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
create cached table T_METADATA ( MET_ID_C varchar(36) not null, MET_NAME_C varchar(50) not null, MET_TYPE_C varchar(20) not null, MET_DELETEDATE_D datetime, primary key (MET_ID_C) );
|
||||
create cached table T_DOCUMENT_METADATA ( DME_ID_C varchar(36) not null, DME_IDDOCUMENT_C varchar(36) not null, DME_IDMETADATA_C varchar(36) not null, DME_VALUE_C varchar(4000) not null, primary key (DME_ID_C) );
|
||||
create cached table T_DOCUMENT_METADATA ( DME_ID_C varchar(36) not null, DME_IDDOCUMENT_C varchar(36) not null, DME_IDMETADATA_C varchar(36) not null, DME_VALUE_C varchar(4000) null, primary key (DME_ID_C) );
|
||||
alter table T_DOCUMENT_METADATA add constraint FK_DME_IDDOCUMENT_C foreign key (DME_IDDOCUMENT_C) references T_DOCUMENT (DOC_ID_C) on delete restrict on update restrict;
|
||||
alter table T_DOCUMENT_METADATA add constraint FK_DME_IDMETADATA_C foreign key (DME_IDMETADATA_C) references T_METADATA (MET_ID_C) on delete restrict on update restrict;
|
||||
update T_CONFIG set CFG_VALUE_C = '24' where CFG_ID_C = 'DB_VERSION';
|
||||
|
||||
Reference in New Issue
Block a user