package edu.asu.diging.gilesecosystem.web.nepomuk.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.asu.diging.gilesecosystem.septemberutil.properties.MessageType;
import edu.asu.diging.gilesecosystem.septemberutil.service.ISystemMessageHandler;
import edu.asu.diging.gilesecosystem.util.properties.IPropertiesManager;
import edu.asu.diging.gilesecosystem.web.domain.IFile;
import edu.asu.diging.gilesecosystem.web.exceptions.NoNepomukFoundException;
import edu.asu.diging.gilesecosystem.web.nepomuk.INepomukUrlService;
import edu.asu.diging.gilesecosystem.web.service.properties.Properties;
import edu.asu.diging.gilesecosystem.web.zookeeper.INepomukServiceDiscoverer;

/**
 * Helper class for Nepomuk URL.
 * 
 * @author jdamerow
 *
 */
@Service
public class NepomukUrlService implements INepomukUrlService {

    @Autowired
    protected INepomukServiceDiscoverer nepomukDiscoverer;
    
    @Autowired
    protected IPropertiesManager propertyManager;
    
    @Autowired
    private ISystemMessageHandler messageHandler;

    /* (non-Javadoc)
     * @see edu.asu.diging.gilesecosystem.web.nepomuk.impl.INepomukUrlService#getFileDownloadPath(edu.asu.diging.gilesecosystem.web.domain.IFile)
     */
    @Override
    public String getFileDownloadPath(IFile file) {
        String nepomukUrl;
        try {
            nepomukUrl = nepomukDiscoverer.getRandomNepomukInstance();
        } catch (NoNepomukFoundException e) {
            messageHandler.handleMessage("Could not download file. Nepomuk could not be reached.", e, MessageType.ERROR);
            return null;
        }
        
        return nepomukUrl + propertyManager.getProperty(Properties.NEPOMUK_FILES_ENDPOINT).replace("{0}", file.getStorageId());
    }
}

@@ -1660,24 +1660,276 @@
  %7D%0A        %0A
+        if (file.getStorageId() == null) %7B%0A            messageHandler.handleMessage(%22Could not download file.%22, %22Could not download file. No storage id present for %22 + file.getId() + %22.%22, MessageType.ERROR);%0A            return null;%0A        %7D%0A        %0A
         retu

fix for no storage id