Search in sources :

Example 1 with IdentifierRange

use of alma.archive.range.IdentifierRange in project ACS by ACS-Community.

the class UIDLibrary method getNewRestrictedRange.

/**
	 * Fetches a new restricted range. 
	 * This will return a URI allowing access to the new Range. 
	 * The range is automatically stored in the archive. 
	 * This method should only be used in very special cases, 
	 * see <a href="http://almasw.hq.eso.org/almasw/bin/view/Archive/UidLibrary">Archive/UidLibrary wiki page</a>!
	 * @param identifier  the identifier archive from which a new <code>Range</code> can be obtained if necessary. Use <br>
	 *        <code>ContainerServices#getTransparentXmlComponent(IdentifierJ.class, identRaw, IdentifierOperations.class);</code> <br>
	 *        to create the required XML binding class aware interface from the plain-Corba <code>Identifier</code> object 
	 *        (<code>identRaw</code>) that is obtained, for example, by <br>
	 *        <code>IdentifierHelper.narrow(getDefaultComponent("IDL:alma/xmlstore/Identifier:1.0"))</code>.
	 * @param printLogs Emit logs, iff set to true.
	 * @return the UID of the range, which can be used for example as an argument in {@link #assignUniqueEntityId(EntityT, URI)}.
	 * @throws UniqueIdException  if the range cannot be obtained from the archive. 
	 */
public URI getNewRestrictedRange(int size, String user, IdentifierJ identifier, boolean printLogs) throws AcsJRangeUnavailableEx, AcsJIdentifierUnexpectedEx {
    Range range = null;
    try {
        if (printLogs)
            logger.finest("UIDLibrary: Fetching a restricted range");
        IdentifierRange idRange = identifier.getNewRestrictedRange(size, user);
        range = new Range(idRange);
    } catch (NotAvailable e) {
        throw new AcsJRangeUnavailableEx(e);
    }
    URI uri = range.rangeId();
    if (idRanges.containsKey(uri)) {
        AcsJIdentifierUnexpectedEx ex = new AcsJIdentifierUnexpectedEx();
        ex.setContextInfo("Cannot store new range. URI occupied. This should never have happened by design!!");
        throw ex;
    }
    if (printLogs)
        logger.finest("UIDLibrary: Storing Range under: " + uri.toASCIIString());
    idRanges.put(uri, range);
    return uri;
}
Also used : NotAvailable(alma.xmlstore.IdentifierPackage.NotAvailable) AcsJRangeUnavailableEx(alma.ArchiveIdentifierError.wrappers.AcsJRangeUnavailableEx) AcsJIdentifierUnexpectedEx(alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnexpectedEx) IdentifierRange(alma.archive.range.IdentifierRange) IdentifierRange(alma.archive.range.IdentifierRange) URI(java.net.URI)

Example 2 with IdentifierRange

use of alma.archive.range.IdentifierRange in project ACS by ACS-Community.

the class UIDLibrary method fetchRange.

/**
	 * Fetch an existing range from the archive and deserialise, only certain
	 * operations will be permitted.
	 * This method should only be used in very special cases, 
	 * see <a href="http://almasw.hq.eso.org/almasw/bin/view/Archive/UidLibrary">Archive/UidLibrary wiki page</a>!
	 * @param uri
	 * @param identifier  the identifier archive from which a new <code>Range</code> can be obtained if necessary. Use <br>
	 *        <code>ContainerServices#getTransparentXmlComponent(IdentifierJ.class, identRaw, IdentifierOperations.class);</code> <br>
	 *        to create the required XML binding class aware interface from the plain-Corba <code>Identifier</code> object 
	 *        (<code>identRaw</code>) that is obtained, for example, by <br>
	 *        <code>IdentifierHelper.narrow(getDefaultComponent("IDL:alma/xmlstore/Identifier:1.0"))</code>.
	 * 
	 * @throws AcsJRangeUnavailableEx
	 */
public void fetchRange(URI uri, String user, IdentifierJ identifier) throws AcsJRangeUnavailableEx {
    IdentifierRange idRange = null;
    try {
        logger.finest("UIDLibrary: Fetching range: " + uri.toASCIIString());
        idRange = identifier.getExistingRange(uri.toASCIIString(), user);
    } catch (NotFound e) {
        throw new AcsJRangeUnavailableEx(e);
    }
    Range r = new Range(idRange);
    if (!refRanges.containsKey(uri)) {
        refRanges.put(uri, r);
    } else {
        AcsJRangeUnavailableEx ex = new AcsJRangeUnavailableEx();
        ex.setRange(uri.toASCIIString());
        throw ex;
    }
}
Also used : AcsJRangeUnavailableEx(alma.ArchiveIdentifierError.wrappers.AcsJRangeUnavailableEx) IdentifierRange(alma.archive.range.IdentifierRange) IdentifierRange(alma.archive.range.IdentifierRange) NotFound(alma.xmlstore.IdentifierPackage.NotFound)

Example 3 with IdentifierRange

use of alma.archive.range.IdentifierRange in project ACS by ACS-Community.

the class IdentifierJMock method getNewRestrictedRange.

/* (non-Javadoc)
	 * @see alma.xmlstore.IdentifierJ#getNewRestrictedRange(int, java.lang.String)
	 */
public IdentifierRange getNewRestrictedRange(int number, String user) throws NotAvailable {
    IdentifierRange range = this.getNewRange();
    RangeT ranget = range.getRange();
    ranget.setMaxDocumentID(Integer.toHexString(number));
    return range;
}
Also used : RangeT(alma.archive.range.RangeT) IdentifierRange(alma.archive.range.IdentifierRange)

Example 4 with IdentifierRange

use of alma.archive.range.IdentifierRange in project ACS by ACS-Community.

the class IdentifierJMock method getNewRange.

/** 
	 * This is the only method that's currently implemented
	 * @see alma.xmlstore.IdentifierJ#getNewRange()
	 */
public IdentifierRange getNewRange() throws NotAvailable {
    //Create the entity information
    IdentifierRangeEntityT entityt = new IdentifierRangeEntityT();
    //The id of the range is the 0 document id in that range.
    entityt.setEntityId(createUid());
    IdentifierRange range = new IdentifierRange();
    range.setIdentifierRangeEntity(entityt);
    //set the time stamp
    // todo: pass in time externally?
    String ts = IsoDateFormat.formatCurrentDate();
    range.setCreatedTimeStamp(ts);
    range.setIsLocked(false);
    String archiveIdString = Long.toHexString(archiveid);
    archiveIdString = "X" + StringUtils.leftPad(archiveIdString, archiveIdLength, '0');
    range.setArchiveID(archiveIdString);
    RangeT ranget = new RangeT();
    ranget.setRangeID(Long.toHexString(rangeid));
    ranget.setBaseDocumentID("1");
    range.setRange(ranget);
    rangeid++;
    return range;
}
Also used : RangeT(alma.archive.range.RangeT) IdentifierRange(alma.archive.range.IdentifierRange) IdentifierRangeEntityT(alma.archive.range.IdentifierRangeEntityT)

Aggregations

IdentifierRange (alma.archive.range.IdentifierRange)4 AcsJRangeUnavailableEx (alma.ArchiveIdentifierError.wrappers.AcsJRangeUnavailableEx)2 RangeT (alma.archive.range.RangeT)2 AcsJIdentifierUnexpectedEx (alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnexpectedEx)1 IdentifierRangeEntityT (alma.archive.range.IdentifierRangeEntityT)1 NotAvailable (alma.xmlstore.IdentifierPackage.NotAvailable)1 NotFound (alma.xmlstore.IdentifierPackage.NotFound)1 URI (java.net.URI)1