use of com.icthh.xm.ms.entity.domain.Attachment in project xm-ms-entity by xm-online.
the class AttachmentResourceIntTest method equalsVerifier.
@Test
@Transactional
public void equalsVerifier() throws Exception {
TestUtil.equalsVerifier(Attachment.class);
Attachment attachment1 = new Attachment();
attachment1.setId(1L);
Attachment attachment2 = new Attachment();
attachment2.setId(attachment1.getId());
assertThat(attachment1).isEqualTo(attachment2);
attachment2.setId(2L);
assertThat(attachment1).isNotEqualTo(attachment2);
attachment1.setId(null);
assertThat(attachment1).isNotEqualTo(attachment2);
}
use of com.icthh.xm.ms.entity.domain.Attachment in project xm-ms-entity by xm-online.
the class DeleteEntityTest method createXmEntity.
private XmEntity createXmEntity() {
XmEntity xmEntity = new XmEntity().key(randomUUID().toString()).typeKey("TEST_DELETE");
xmEntity.name("name").functionContexts(asSet(new FunctionContext().key("1").typeKey("A").xmEntity(xmEntity), new FunctionContext().key("2").typeKey("A").xmEntity(xmEntity), new FunctionContext().key("3").typeKey("A").xmEntity(xmEntity))).attachments(asSet(new Attachment().typeKey("A").name("1"), new Attachment().typeKey("A").name("2"), new Attachment().typeKey("A").name("3"))).calendars(asSet(new Calendar().typeKey("A").name("1").events(asSet(new Event().typeKey("A").title("1"), new Event().typeKey("A").title("2"))), new Calendar().typeKey("A").name("2").events(asSet(new Event().typeKey("A").title("3"), new Event().typeKey("A").title("4"))))).locations(asSet(new Location().typeKey("A").name("1"), new Location().typeKey("A").name("2"))).ratings(asSet(new Rating().typeKey("A").votes(asSet(new Vote().message("1").value(1.1).userKey("1"), new Vote().message("2").value(2.1).userKey("2"))))).tags(asSet(new Tag().typeKey("A").name("1"), new Tag().typeKey("A").name("2"))).comments(asSet(new Comment().message("1").userKey("1"), new Comment().message("2").userKey("1")));
return xmEntity;
}
use of com.icthh.xm.ms.entity.domain.Attachment in project xm-ms-entity by xm-online.
the class EntityServiceImplIntTest method saveSelfLinkTarget.
@Test
@Transactional
@WithMockUser(authorities = "SUPER-ADMIN")
public void saveSelfLinkTarget() throws Exception {
when(storageService.store(Mockito.any(MultipartFile.class), Mockito.any())).thenReturn("test.txt");
int databaseSizeBeforeCreate = linkRepository.findAll().size();
XmEntity targetEntity = xmEntityRepository.save(createEntity(2l, TARGET_TYPE_KEY));
Link link = createSelfLink(targetEntity);
// Create link with attachment
MockMultipartFile file = new MockMultipartFile("file", "test.txt", "text/plain", "TEST".getBytes());
xmEntityService.saveLinkTarget(IdOrKey.SELF, link, file);
// Validate the link in the database
List<Link> linkList = linkRepository.findAll();
assertThat(linkList).hasSize(databaseSizeBeforeCreate + BigInteger.ONE.intValue());
// validate attachment in database
List<Attachment> attachments = attachmentService.findAll(null);
assertThat(attachments).hasSize(BigInteger.ONE.intValue());
Attachment attachment = attachments.stream().findFirst().get();
assertThat(attachment.getContentUrl()).contains("test.txt");
}
use of com.icthh.xm.ms.entity.domain.Attachment in project xm-ms-entity by xm-online.
the class XmEntityServiceImpl method saveXmEntity.
/**
* Save a xmEntity.
* When you call this method will be run general save LEP
*
* @param xmEntity the entity to save
* @return the persisted entity
*/
@LogicExtensionPoint("Save")
public XmEntity saveXmEntity(XmEntity xmEntity) {
log.debug("Request to save XmEntity : {}", xmEntity);
Optional<XmEntity> oldEntity = startUpdateDateGenerationStrategy.preProcessStartUpdateDates(xmEntity, xmEntity.getId(), xmEntityRepository, XmEntity::setStartDate, XmEntity::getStartDate, XmEntity::setUpdateDate);
if (oldEntity.isPresent()) {
preventRenameTenant(xmEntity, oldEntity.get());
} else if (xmEntity.getCreatedBy() == null) {
xmEntity.setCreatedBy(authContextHolder.getContext().getUserKey().orElse(null));
}
// FIXME It is hack to link each tag with entity before persisting. may be there is more elegant solution.
xmEntity.updateXmEntityReference(xmEntity.getAttachments(), Attachment::setXmEntity);
xmEntity.updateXmEntityReference(xmEntity.getCalendars(), Calendar::setXmEntity);
xmEntity.updateXmEntityReference(xmEntity.getLocations(), Location::setXmEntity);
xmEntity.updateXmEntityReference(xmEntity.getRatings(), Rating::setXmEntity);
xmEntity.updateXmEntityReference(xmEntity.getTags(), Tag::setXmEntity);
xmEntity.updateXmEntityReference(xmEntity.getComments(), Comment::setXmEntity);
xmEntity.updateXmEntityReference(xmEntity.getTargets(), Link::setSource);
xmEntity.updateXmEntityReference(xmEntity.getSources(), Link::setTarget);
xmEntity.updateXmEntityReference(xmEntity.getVotes(), Vote::setXmEntity);
XmEntity result = xmEntityRepository.save(xmEntity);
xmEntitySearchRepository.save(result);
return result;
}
Aggregations