Commit a67d09ac authored by Maxym Borodenko's avatar Maxym Borodenko

Merge branch 'ui-124-inventory-group-form' into 'master'

Inventory group: Clear inventory map before deleting group data

Closes #107

See merge request !117
parents 96ec6f45 66c37a10
......@@ -15,6 +15,7 @@
*/
package org.gringlobal.persistence;
import org.gringlobal.model.AccessionInvGroup;
import org.gringlobal.model.AccessionInvGroupMap;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
......@@ -23,4 +24,7 @@ import org.springframework.stereotype.Repository;
@Repository
public interface AccessionInvGroupMapRepository extends JpaRepository<AccessionInvGroupMap, Long>, QuerydslPredicateExecutor<AccessionInvGroupMap> {
/// Delete members of inventory group
int deleteByAccessionInvGroup(AccessionInvGroup entity);
}
......@@ -78,6 +78,16 @@ public class AccessionInvGroupServiceImpl extends FilteredCRUDServiceImpl<Access
return saved;
}
/**
* Override to clear {@link AccessionInvGroup#members}
*/
@Override
@Transactional
public AccessionInvGroup remove(AccessionInvGroup entity) {
accessionInvGroupMapRepository.deleteByAccessionInvGroup(entity);
return super.remove(entity);
}
@Override
public Page<AccessionInvGroup> list(AccessionInvGroupFilter filter, Pageable page) throws SearchException {
return super.list(AccessionInvGroup.class, filter, page);
......
/*
* Copyright 2020 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gringlobal.test.service;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import java.util.List;
import org.gringlobal.model.AccessionInvGroup;
import org.gringlobal.model.Inventory;
import org.gringlobal.persistence.AccessionInvGroupMapRepository;
import org.gringlobal.persistence.AccessionInvGroupRepository;
import org.gringlobal.service.AccessionInvGroupService;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithUserDetails;
import org.springframework.transaction.annotation.Transactional;
@WithUserDetails(value = AbstractServicesTest.USER_CURATOR1)
public class AccessionInvGroupServiceTest extends AbstractServicesTest {
@Autowired
private AccessionInvGroupMapRepository accessionInvGroupMapRepository;
@Autowired
private AccessionInvGroupRepository accessionInvGroupRepository;
@Autowired
private AccessionInvGroupService accessionInvGroupService;
@After
@Transactional
public void cleanup() throws Exception {
accessionInvGroupRepository.deleteAll();
accessionInvGroupMapRepository.deleteAll();
inventoryRepository.deleteAll();
accessionRepository.deleteAll();
taxonomySpeciesRepository.deleteAll();
taxonomyGenusRepository.deleteAll();
taxonomyFamilyRepository.deleteAll();
super.cleanup();
}
@Test
public void deleteAccessionInvGroupWithMembersTest() {
Inventory inventory = addInventoryToDB(addAccessionToDB());
AccessionInvGroup accessionInvGroup = new AccessionInvGroup();
accessionInvGroup.setGroupName("TestGroup");
accessionInvGroup = accessionInvGroupService.create(accessionInvGroup);
assertThat(accessionInvGroupRepository.count(), is(1L));
accessionInvGroupService.addMembers(accessionInvGroup, List.of(inventory), "test note");
assertThat(accessionInvGroupMapRepository.count(), is(1L));
accessionInvGroupService.remove(accessionInvGroup);
assertThat(accessionInvGroupRepository.count(), is(0L));
assertThat(accessionInvGroupMapRepository.count(), is(0L));
}
}
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