Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: geonetwork/core-geonetwork
...
head fork: geonetwork/core-geonetwork
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
4 core/src/main/java/org/fao/geonet/kernel/DataManager.java
@@ -1210,9 +1210,7 @@ public void apply(Metadata metadata) {
MetadataHarvestInfo harvestInfo = metadata.getHarvestInfo();
harvestInfo.setUuid(harvestUuid);
harvestInfo.setHarvested(harvestUuid != null);
- if (harvestUri.isPresent()) {
- harvestInfo.setUri(harvestUri.get());
- }
+ harvestInfo.setUri(harvestUri.orNull());
}
});
}
View
11 core/src/main/java/org/fao/geonet/resources/Resources.java
@@ -295,8 +295,15 @@ private static File locateResource(String resourcesDir,
}
final int indexOfDot = file.getName().lastIndexOf(".");
- final String suffixless = file.getName().substring(0, indexOfDot);
- String suffix = file.getName().substring(indexOfDot + 1);
+ final String suffixless;
+ String suffix;
+ if (indexOfDot == -1) {
+ suffixless = file.getName();
+ suffix = ".png";
+ } else {
+ suffixless = file.getName().substring(0, indexOfDot);
+ suffix = file.getName().substring(indexOfDot + 1);
+ }
if (!file.exists() && IMAGE_WRITE_SUFFIXES.contains(suffix.toLowerCase())) {
// find a different format and convert it to our desired format
File[] found = file.getParentFile().listFiles(new FilenameFilter() {
View
6 core/src/test/java/org/fao/geonet/AbstractCoreIntegrationTest.java
@@ -439,7 +439,7 @@ public User loginAsAdmin(ServiceContext context) {
return admin;
}
- protected Element getSampleMetadataXml() throws IOException, JDOMException {
+ public Element getSampleMetadataXml() throws IOException, JDOMException {
final URL resource = AbstractCoreIntegrationTest.class.getResource("kernel/valid-metadata.iso19139.xml");
return Xml.loadStream(resource.openStream());
}
@@ -450,8 +450,8 @@ protected Element getSampleMetadataXml() throws IOException, JDOMException {
* @return
* @throws Exception
*/
- protected int importMetadataXML(ServiceContext context, String uuid, InputStream xmlInputStream, MetadataType metadataType,
- int groupId, String uuidAction) throws Exception {
+ public int importMetadataXML(ServiceContext context, String uuid, InputStream xmlInputStream, MetadataType metadataType,
+ int groupId, String uuidAction) throws Exception {
final Element metadata = Xml.loadStream(xmlInputStream);
final DataManager dataManager = _applicationContext.getBean(DataManager.class);
String schema = dataManager.autodetectSchema(metadata);
View
74 core/src/test/java/org/fao/geonet/kernel/DataManagerIntegrationTest.java
@@ -1,20 +1,20 @@
package org.fao.geonet.kernel;
import static org.junit.Assert.*;
+
+import com.google.common.base.Optional;
import jeeves.server.UserSession;
import jeeves.server.context.ServiceContext;
import org.fao.geonet.AbstractCoreIntegrationTest;
import org.fao.geonet.constants.Params;
import org.fao.geonet.domain.*;
-import org.fao.geonet.repository.GroupRepository;
-import org.fao.geonet.repository.MetadataCategoryRepository;
-import org.fao.geonet.repository.MetadataRepository;
-import org.fao.geonet.repository.SourceRepository;
+import org.fao.geonet.repository.*;
import org.fao.geonet.utils.Xml;
import org.jdom.Element;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import javax.annotation.Nonnull;
import java.io.ByteArrayInputStream;
import java.util.UUID;
@@ -88,10 +88,7 @@ public void testSetStatus() throws Exception {
final ServiceContext serviceContext = createServiceContext();
loginAsAdmin(serviceContext);
- final Element sampleMetadataXml = super.getSampleMetadataXml();
- final ByteArrayInputStream stream = new ByteArrayInputStream(Xml.getString(sampleMetadataXml).getBytes("UTF-8"));
- final int metadataId = importMetadataXML(serviceContext, "uuidSetStatus", stream, MetadataType.METADATA,
- ReservedGroup.all.getId(), Params.GENERATE_UUID);
+ final int metadataId = importMetadata(this, serviceContext);
final MetadataStatus status = _dataManager.getStatus(metadataId);
@@ -109,8 +106,69 @@ public void testSetStatus() throws Exception {
assertEquals(metadataId, loadedStatus.getId().getMetadataId());
assertEquals(0, loadedStatus.getId().getStatusId());
assertEquals(serviceContext.getUserSession().getUserIdAsInt(), loadedStatus.getId().getUserId());
+ }
+
+ @Test
+ public void testSetHarvesterData() throws Exception {
+ final ServiceContext serviceContext = createServiceContext();
+ loginAsAdmin(serviceContext);
+
+ final int metadataId = importMetadata(this, serviceContext);
+
+ doSetHarvesterDataTest(_metadataRepository, _dataManager, metadataId);
+ }
+ static void doSetHarvesterDataTest(MetadataRepository metadataRepository, DataManager dataManager, int metadataId) throws Exception {
+ Metadata metadata = metadataRepository.findOne(metadataId);
+
+ assertNull(metadata.getHarvestInfo().getUuid());
+ assertNull(metadata.getHarvestInfo().getUri());
+ assertFalse(metadata.getHarvestInfo().isHarvested());
+
+ final String harvesterUuid = "harvesterUuid";
+ dataManager.setHarvestedExt(metadataId, harvesterUuid);
+ metadata = metadataRepository.findOne(metadataId);
+ assertEquals(harvesterUuid, metadata.getHarvestInfo().getUuid());
+ assertTrue(metadata.getHarvestInfo().isHarvested());
+ assertNull(metadata.getHarvestInfo().getUri());
+
+
+ final String newSource = "newSource";
+ // check that another update doesn't break the last setting
+ // there used to a bug where this was the case because entity manager wasn't being flushed
+ metadataRepository.update(metadataId, new Updater<Metadata>() {
+ @Override
+ public void apply(@Nonnull Metadata entity) {
+ entity.getSourceInfo().setSourceId(newSource);
+ }
+ });
+
+ assertEquals(newSource, metadata.getSourceInfo().getSourceId());
+ assertEquals(harvesterUuid, metadata.getHarvestInfo().getUuid());
+ assertTrue(metadata.getHarvestInfo().isHarvested());
+ assertNull(metadata.getHarvestInfo().getUri());
+
+ final String harvesterUuid2 = "harvesterUuid2";
+ final String harvesterUri = "harvesterUri";
+ dataManager.setHarvestedExt(metadataId, harvesterUuid2, Optional.of(harvesterUri));
+ metadata = metadataRepository.findOne(metadataId);
+ assertEquals(harvesterUuid2, metadata.getHarvestInfo().getUuid());
+ assertTrue(metadata.getHarvestInfo().isHarvested());
+ assertEquals(harvesterUri, metadata.getHarvestInfo().getUri());
+
+ dataManager.setHarvestedExt(metadataId, null);
+ metadata = metadataRepository.findOne(metadataId);
+ assertNull(metadata.getHarvestInfo().getUuid());
+ assertNull(metadata.getHarvestInfo().getUri());
+ assertFalse(metadata.getHarvestInfo().isHarvested());
+ }
+ static int importMetadata(AbstractCoreIntegrationTest test, ServiceContext serviceContext) throws Exception {
+ final Element sampleMetadataXml = test.getSampleMetadataXml();
+ final ByteArrayInputStream stream = new ByteArrayInputStream(Xml.getString(sampleMetadataXml).getBytes("UTF-8"));
+ return test.importMetadataXML(serviceContext, "uuidSetStatus", stream, MetadataType.METADATA,
+ ReservedGroup.all.getId(), Params.GENERATE_UUID);
}
+
}
View
25 ...anagerWorksWithoutTransactionIntegrationTest.java → ...anagerWorksWithoutTransactionIntegrationTest.java
@@ -1,11 +1,13 @@
-package org.fao.geonet;
+package org.fao.geonet.kernel;
import jeeves.server.UserSession;
import jeeves.server.context.ServiceContext;
+import org.fao.geonet.AbstractCoreIntegrationTest;
import org.fao.geonet.domain.ISODate;
import org.fao.geonet.domain.Metadata;
import org.fao.geonet.domain.MetadataType;
import org.fao.geonet.kernel.DataManager;
+import org.fao.geonet.repository.MetadataRepository;
import org.jdom.Element;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,6 +26,8 @@
public class DataManagerWorksWithoutTransactionIntegrationTest extends AbstractCoreIntegrationTest {
@Autowired
DataManager _dataManager;
+ @Autowired
+ MetadataRepository _metadataRepository;
@Autowired
PlatformTransactionManager _tm;
@@ -57,4 +61,23 @@ public void run() throws Exception {
}
+ @Test
+ public void testSetHarvesterData() throws Exception {
+ TransactionlessTesting.get().run
+ (new TestTask() {
+ @Override
+ public void run() throws Exception {
+ final ServiceContext serviceContext = createServiceContext();
+ loginAsAdmin(serviceContext);
+
+ final DataManagerWorksWithoutTransactionIntegrationTest test =
+ DataManagerWorksWithoutTransactionIntegrationTest.this;
+ final int metadataId = DataManagerIntegrationTest.importMetadata(test, serviceContext);
+
+ DataManagerIntegrationTest.doSetHarvesterDataTest(_metadataRepository, _dataManager, metadataId);
+ }
+ });
+
+ }
+
}
View
1  domain/src/main/java/org/fao/geonet/repository/GeonetRepositoryImpl.java
@@ -49,6 +49,7 @@ public T update(ID id, Updater<T> updater) {
updater.apply(entity);
_entityManager.persist(entity);
+ _entityManager.flush();
return entity;
}
View
2  harvesters/src/main/java/org/fao/geonet/kernel/harvest/harvester/csw/Aligner.java
@@ -232,7 +232,7 @@ private void addMetadata(RecordInfo ri) throws Exception
}
String id = dataMan.insertMetadata(context, schema, md, ri.uuid,
ownerId, group, params.uuid,
- isTemplate, docType, category, ri.changeDate, ri.changeDate, ufo, indexImmediate);
+ isTemplate, docType, category, ri.changeDate, ri.changeDate, ufo, indexImmediate);
int iId = Integer.parseInt(id);

No commit comments for this range

Something went wrong with that request. Please try again.