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;
}
}
Aggregations