Search in sources :

Example 1 with UIDLibrary

use of alma.acs.container.archive.UIDLibrary in project ACS by ACS-Community.

the class ContainerServicesImpl method assignUniqueEntityId.

/**
	 * @see alma.acs.container.ContainerServices#assignUniqueEntityId(EntityT)
	 */
@Override
public void assignUniqueEntityId(EntityT entity) throws AcsJContainerServicesEx {
    if (entity == null) {
        AcsJBadParameterEx cause = new AcsJBadParameterEx();
        cause.setParameter("entity");
        cause.setParameterValue("null");
        throw new AcsJContainerServicesEx(cause);
    }
    if (fakeUIDsForTesting) {
        long localId = (new Random(System.currentTimeMillis())).nextLong();
        String uid = Range.generateUID("testArchiveId", "testRangeId", localId);
        entity.setEntityId(uid);
        return;
    }
    try {
        if (identifierArchive == null) {
            Identifier identRaw = IdentifierHelper.narrow(getDefaultComponent("IDL:alma/xmlstore/Identifier:1.0"));
            identifierArchive = getTransparentXmlWrapper(IdentifierJ.class, identRaw, IdentifierOperations.class);
        }
        if (uidLibrary == null) {
            uidLibrary = new UIDLibrary(m_logger);
        }
        uidLibrary.assignUniqueEntityId(entity, identifierArchive);
    } catch (Throwable thr) {
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx(thr);
        String msg = "Failed to assign a UID to entity of type ";
        if (entity.getEntityTypeName() != null) {
            msg += entity.getEntityTypeName();
        } else {
            msg += entity.getClass().getSimpleName();
        }
        ex.setContextInfo(msg);
        throw ex;
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) Identifier(alma.xmlstore.Identifier) Random(java.util.Random) IdentifierJ(alma.xmlstore.IdentifierJ) IdentifierOperations(alma.xmlstore.IdentifierOperations) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) UIDLibrary(alma.acs.container.archive.UIDLibrary) CBlong(alma.ACS.CBlong)

Aggregations

CBlong (alma.ACS.CBlong)1 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)1 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)1 UIDLibrary (alma.acs.container.archive.UIDLibrary)1 Identifier (alma.xmlstore.Identifier)1 IdentifierJ (alma.xmlstore.IdentifierJ)1 IdentifierOperations (alma.xmlstore.IdentifierOperations)1 Random (java.util.Random)1