From e1c86541ccf47f8cd7d9a420095c8fc0c2d5af74 Mon Sep 17 00:00:00 2001 From: seustachi Date: Tue, 26 Aug 2014 16:54:44 +0200 Subject: [PATCH] https://github.com/OCHA-DAP/DAP-System/issues/256 --- .../dao/metadata/DataSerieMetadataDAO.java | 2 ++ .../dao/metadata/DataSerieMetadataDAOImpl.java | 6 ++++++ .../ocha/hdx/service/CuratedDataServiceImpl.java | 1 + .../dao/metadata/DataSerieMetadataDAOImplTest.java | 13 +++++++++++++ 4 files changed, 22 insertions(+) diff --git a/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/metadata/DataSerieMetadataDAO.java b/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/metadata/DataSerieMetadataDAO.java index 2ce1c0e1..84b6eb18 100644 --- a/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/metadata/DataSerieMetadataDAO.java +++ b/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/metadata/DataSerieMetadataDAO.java @@ -48,4 +48,6 @@ public interface DataSerieMetadataDAO { public DataSerieMetadata getDataSerieMetadataByIndicatorTypeCodeAndSourceCodeAndEntryKey(final String indicatorTypeCode, final String sourceCode, final MetadataName entryKey); + public void deleteDataSerieMetadataForIndicatorType(long indicatorTypeId); + } diff --git a/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/metadata/DataSerieMetadataDAOImpl.java b/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/metadata/DataSerieMetadataDAOImpl.java index d94ff3a9..11588c9e 100644 --- a/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/metadata/DataSerieMetadataDAOImpl.java +++ b/HDX-System/src/main/java/org/ocha/hdx/persistence/dao/metadata/DataSerieMetadataDAOImpl.java @@ -129,4 +129,10 @@ public DataSerieMetadata getDataSerieMetadataByIndicatorTypeCodeAndSourceCodeAnd } } + @Override + @Transactional + public void deleteDataSerieMetadataForIndicatorType(final long indicatorTypeId) { + em.createQuery("DELETE FROM DataSerieMetadata ad WHERE ad.indicatorType.id=:indicatorTypeId").setParameter("indicatorTypeId", indicatorTypeId).executeUpdate(); + + } } diff --git a/HDX-System/src/main/java/org/ocha/hdx/service/CuratedDataServiceImpl.java b/HDX-System/src/main/java/org/ocha/hdx/service/CuratedDataServiceImpl.java index 5d50c92b..1b3ed98f 100644 --- a/HDX-System/src/main/java/org/ocha/hdx/service/CuratedDataServiceImpl.java +++ b/HDX-System/src/main/java/org/ocha/hdx/service/CuratedDataServiceImpl.java @@ -292,6 +292,7 @@ public void updateIndicatorType(final long indicatorTypeId, final String newCode @Override @Transactional public void deleteIndicatorType(final long indicatorTypeId) { + dataSerieMetadataDAO.deleteDataSerieMetadataForIndicatorType(indicatorTypeId); indicatorTypeDAO.deleteIndicatorType(indicatorTypeId); } diff --git a/HDX-System/src/test/java/org/ocha/hdx/persistence/dao/metadata/DataSerieMetadataDAOImplTest.java b/HDX-System/src/test/java/org/ocha/hdx/persistence/dao/metadata/DataSerieMetadataDAOImplTest.java index cc595f00..90fd75a0 100644 --- a/HDX-System/src/test/java/org/ocha/hdx/persistence/dao/metadata/DataSerieMetadataDAOImplTest.java +++ b/HDX-System/src/test/java/org/ocha/hdx/persistence/dao/metadata/DataSerieMetadataDAOImplTest.java @@ -288,6 +288,19 @@ public final void testDeleteDataSerieMetadata() { textDAO.deleteText(text.getId()); } + @Test + public final void testDeleteDataSerieMetadataForIndicatorType() { + + final Text text = textDAO.createText("Dummy Value"); + final DataSerieMetadata dataSerieMetadata = dataSerieMetadataDAO.createDataSerieMetadata(indicatorType, source, MetadataName.METHODOLOGY, text); + assertTrue(dataSerieMetadata.getId() > 0); + + dataSerieMetadataDAO.deleteDataSerieMetadataForIndicatorType(indicatorType.getId()); + + assertNull(dataSerieMetadataDAO.getDataSerieMetadataById(dataSerieMetadata.getId())); + + } + /** * Test method for {@link org.ocha.hdx.persistence.dao.metadata.DataSerieMetadataDAOImpl#updateDataSerieMetadata(long, org.ocha.hdx.persistence.entity.i18n.Text)}. */