Search in sources :

Example 1 with MCRConfiguration

use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.

the class MCRXMLMetadataManager method reload.

/**
 * Reads configuration properties, checks and creates base directories and builds the singleton
 */
public synchronized void reload() {
    MCRConfiguration config = MCRConfiguration.instance();
    String pattern = config.getString("MCR.Metadata.ObjectID.NumberPattern", "0000000000");
    defaultLayout = pattern.length() - 4 + "-2-2";
    String base = config.getString("MCR.Metadata.Store.BaseDir");
    baseDir = new File(base);
    checkDir(baseDir, "base");
    defaultClass = config.getClass("MCR.Metadata.Store.DefaultClass", MCRVersioningMetadataStore.class);
    if (MCRVersioningMetadataStore.class.isAssignableFrom(defaultClass)) {
        try {
            String svnBaseValue = config.getString("MCR.Metadata.Store.SVNBase");
            if (!svnBaseValue.endsWith("/")) {
                svnBaseValue += '/';
            }
            svnBase = new URI(svnBaseValue);
            LOGGER.info("SVN Base: {}", svnBase);
            if (svnBase.getScheme() == null) {
                String workingDirectory = (new File(".")).getAbsolutePath();
                URI root = new File(MCRConfiguration.instance().getString("MCR.datadir", workingDirectory)).toURI();
                URI resolved = root.resolve(svnBase);
                LOGGER.warn("Resolved {} to {}", svnBase, resolved);
                svnBase = resolved;
            }
        } catch (URISyntaxException ex) {
            String msg = "Syntax error in MCR.Metadata.Store.SVNBase property: " + svnBase;
            throw new MCRConfigurationException(msg, ex);
        }
        if (svnBase.getScheme().equals("file")) {
            svnDir = new File(svnBase);
            checkDir(svnDir, "svn");
        }
    }
    closeCreatedStores();
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration) MCRVersioningMetadataStore(org.mycore.datamodel.ifs2.MCRVersioningMetadataStore) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI)

Example 2 with MCRConfiguration

use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.

the class MCRXMLMetadataManager method setupStore.

@SuppressWarnings("unchecked")
private void setupStore(String project, String objectType, String configPrefix) throws ReflectiveOperationException {
    MCRConfiguration config = MCRConfiguration.instance();
    String baseID = getStoryKey(project, objectType);
    Class clazz = config.getClass(configPrefix + "Class", null);
    if (clazz == null) {
        config.set(configPrefix + "Class", defaultClass.getName());
        clazz = defaultClass;
    }
    if (MCRVersioningMetadataStore.class.isAssignableFrom(clazz)) {
        String property = configPrefix + "SVNRepositoryURL";
        String svnURL = config.getString(property, null);
        if (svnURL == null) {
            String relativeURI = MessageFormat.format("{0}/{1}/", project, objectType);
            URI repURI = svnBase.resolve(relativeURI);
            LOGGER.info("Resolved {} to {} for {}", relativeURI, repURI.toASCIIString(), property);
            config.set(property, repURI.toASCIIString());
            File projectDir = new File(svnDir, project);
            if (!projectDir.exists() && !projectDir.mkdirs()) {
                throwStoreDirException(projectDir, project, objectType, configPrefix);
            }
        }
    }
    String slotLayout = config.getString(configPrefix + "SlotLayout", null);
    if (slotLayout == null) {
        config.set(configPrefix + "SlotLayout", defaultLayout);
    }
    File projectDir = new File(baseDir, project);
    File typeDir = new File(projectDir, objectType);
    if (!typeDir.exists() && !typeDir.mkdirs()) {
        throwStoreDirException(typeDir, project, objectType, configPrefix);
    }
    config.set(configPrefix + "BaseDir", typeDir.getAbsolutePath());
    config.set(configPrefix + "ForceXML", true);
    config.set(configPrefix + "ForceDocType", objectType.equals("derivate") ? "mycorederivate" : "mycoreobject");
    createdStores.add(baseID);
    MCRStoreManager.createStore(baseID, clazz);
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration) URI(java.net.URI) File(java.io.File)

Example 3 with MCRConfiguration

use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.

the class MCRPackerManagerTest method testPackerConfigurationStart.

@Test
public void testPackerConfigurationStart() throws Exception {
    MCRConfiguration mcrConfiguration = MCRConfiguration.instance();
    String testPackerPrefix = MCRPacker.PACKER_CONFIGURATION_PREFIX + TEST_PACKER_ID + ".";
    Map<String, String> parameterMap = new Hashtable<>();
    // add packer parameter
    parameterMap.put("packer", TEST_PACKER_ID);
    // add test parameter
    parameterMap.put(MCRPackerMock.TEST_PARAMETER_KEY, MCRPackerMock.TEST_VALUE);
    MCRJob packerJob = MCRPackerManager.startPacking(parameterMap);
    Assert.assertNotNull("The Packer job is not present!", packerJob);
    endTransaction();
    Thread.sleep(1000);
    startNewTransaction();
    int waitTime = 10;
    while (waitTime > 0 && !mcrConfiguration.getBoolean(MCRPackerMock.FINISHED_PROPERTY, false) && !mcrConfiguration.getBoolean(MCRPackerMock.SETUP_CHECKED_PROPERTY, false)) {
        Thread.sleep(1000);
        waitTime -= 1;
    }
    Assert.assertTrue("PackerJob did not finish in time!", waitTime > 0);
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration) Hashtable(java.util.Hashtable) MCRJob(org.mycore.services.queuedjob.MCRJob) Test(org.junit.Test)

Example 4 with MCRConfiguration

use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.

the class MCRIdentifierTypeFactory method buildIdentifierType.

private MCRIdentifierType buildIdentifierType(String typeID) {
    MCRConfiguration config = MCRConfiguration.instance();
    String defaultXPath = MessageFormat.format(DEFAULT_XPATH, typeID);
    String xPath = config.getString("MCR.MODS.EnrichmentResolver.IdentifierType." + typeID, defaultXPath);
    return new MCRIdentifierType(typeID, xPath);
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration)

Example 5 with MCRConfiguration

use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.

the class MCRAVExtRealHelix method init.

@Override
public void init(MCRFile file) throws MCRPersistenceException {
    super.init(file);
    MCRConfiguration config = MCRConfiguration.instance();
    String prefix = "MCR.IFS.AVExtender." + file.getStoreID() + ".";
    baseMetadata = config.getString(prefix + "ViewSourceBaseURL");
    try {
        String data = getMetadata(baseMetadata + file.getStorageID());
        String sSize = getBetween("File Size:</strong>", "Bytes", data, "0");
        String sBitRate = getBetween("Bit Rate:</strong>", "Kbps", data, "0.0");
        String sFrameRate = getBetween("Frame Rate: </strong>", "fps", data, "0.0");
        String sDuration = getBetween("Duration:</strong>", "<br>", data, "0:0.0");
        String sType = getBetween("Stream:</strong>", "<br>", data, "");
        bitRate = Math.round(1024 * Float.valueOf(sBitRate));
        StringTokenizer st1 = new StringTokenizer(sFrameRate, " ,");
        while (st1.hasMoreTokens()) {
            double value = Double.valueOf(st1.nextToken());
            frameRate = Math.max(frameRate, value);
        }
        hasVideo = frameRate > 0;
        StringTokenizer st2 = new StringTokenizer(sDuration, ":.");
        durationMinutes = Integer.parseInt(st2.nextToken());
        durationSeconds = Integer.parseInt(st2.nextToken());
        if (Integer.parseInt(st2.nextToken()) > 499) {
            durationSeconds += 1;
            if (durationSeconds > 59) {
                durationMinutes += 1;
                durationSeconds = 0;
            }
        }
        StringTokenizer st3 = new StringTokenizer(sSize, ",");
        StringBuilder sb = new StringBuilder();
        while (st3.hasMoreTokens()) {
            sb.append(st3.nextToken());
        }
        size = Long.parseLong(sb.toString());
        durationHours = durationMinutes / 60;
        durationMinutes = durationMinutes - durationHours * 60;
        if (sType.contains("MPEG Layer 3")) {
            contentTypeID = "mp3";
            hasVideo = false;
        } else if (sType.contains("3GPP")) {
            contentTypeID = "3gp";
            hasVideo = true;
        } else if (sType.contains("MPEG4")) {
            contentTypeID = "mpeg4";
            hasVideo = true;
        } else if (sType.contains("MPEG")) {
            contentTypeID = "mpegvid";
            hasVideo = true;
        } else if (sType.contains("RealVideo")) {
            contentTypeID = "realvid";
        } else if (sType.contains("RealAudio")) {
            contentTypeID = "realaud";
        } else if (sType.contains("Wave File")) {
            contentTypeID = "wav";
            hasVideo = false;
        } else // should be one of "wma" "wmv" "asf"
        {
            contentTypeID = file.getContentTypeID();
            hasVideo = !contentTypeID.equals("wma");
        }
        if (" wma wmv asf asx ".contains(" " + contentTypeID + " ")) {
            basePlayerStarter = config.getString(prefix + "AsxGenBaseURL");
            playerDownloadURL = config.getString(prefix + "MediaPlayerURL");
        } else {
            basePlayerStarter = config.getString(prefix + "RamGenBaseURL");
            playerDownloadURL = config.getString(prefix + "RealPlayerURL");
        }
        URLConnection con = getConnection(basePlayerStarter + file.getStorageID());
        playerStarterCT = con.getContentType();
    } catch (Exception exc) {
        String msg = "Error parsing metadata from Real Server ViewSource: " + file.getStorageID();
        LOGGER.warn(msg, exc);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) MCRConfiguration(org.mycore.common.config.MCRConfiguration) URLConnection(java.net.URLConnection) MCRPersistenceException(org.mycore.common.MCRPersistenceException) IOException(java.io.IOException)

Aggregations

MCRConfiguration (org.mycore.common.config.MCRConfiguration)26 File (java.io.File)3 ArrayList (java.util.ArrayList)3 MCRConfigurationException (org.mycore.common.config.MCRConfigurationException)3 URI (java.net.URI)2 Hashtable (java.util.Hashtable)2 Test (org.junit.Test)2 CategoryDAOMock (org.mycore.frontend.classeditor.mocks.CategoryDAOMock)2 Gson (com.google.gson.Gson)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 URLConnection (java.net.URLConnection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1