Class TemporaryIdentifiersManager<INT>
- java.lang.Object
-
- jetbrains.buildServer.serverSide.identifiers.TemporaryIdentifiersManager<INT>
-
- All Implemented Interfaces:
ExternalIdGenerator,IdentifiersManager<INT>
public class TemporaryIdentifiersManager<INT> extends Object implements IdentifiersManager<INT>
Allows registering new extId-configId pairs without writing them into DB.
-
-
Constructor Summary
Constructors Constructor Description TemporaryIdentifiersManager(BaseIdentifiersManager<INT> delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description INTconfigIdToInternal(String configId)Looks for the internal identifier by the given config id.voidconsumeEntityIds(Consumer<EntityId<INT>> consumer)Consumes entityIds in this managerbooleanexternalIdSatisfiesConvention(String externalId, String entityName, String parentExtId)Returns true if provided external id satisfies convention used to generate new idsINTexternalToInternal(String extId)Looks for the internal identifier by the given external one.List<INT>externalToInternal(List<String> extIds)Looks for the internal identifiers by the given external onesEntityId<INT>findEntityIdByConfigId(String configId)Looks for a registered entity id by the given config id.EntityId<INT>findEntityIdByExternalId(String extId)Looks for a registered entity id by the given external id.EntityId<INT>findEntityIdByInternalId(INT intId)Looks for a registered entity id by the given internal id.EntityId<INT>generateAndRegisterBrandNewExternalId(String parentExtId, String name)Generates a unique external identifier by the given parent external identifier and a user string (usually name), and register the just generated identifier as a brand new one.StringgenerateNewExternalId(String parentExtId, String name, Set<String> excludeAdditionalIds)Generates a new external id based on the given name and (optionally) parent external id.StringgenerateNewExternalId(String parentExtId, String name, Set<String> excludeIds, boolean adjustCase)Generates a new external id based on the given name and (optionally) parent external id.INTgenerateNewIntId(String newExtId)Set<String>getAllExternalIds()Provides with all known external identifiers.Set<String>getAllExternalIds(INT intId)Returns all external ids that correspond to theintId.Set<INT>getAllInternalIds()Provides with all known internal identifiers.Map<String,EntityId<INT>>getNewConfigIds()Set<EntityId<INT>>getNewEntities()Collection<EntityId<INT>>getNewOrChangedEntities()StringinternalToExternal(INT intId)Looks for the external identifier by the given internal one.List<String>internalToExternal(List<INT> intIds)Looks for the external identifiers by the given internal ones.booleanisExternalIdAlias(String externalId)Check whether the external id is an alias (but not a primary external id).voidmarkRemoved(EntityId<INT> entityId, String originProjectIntId)Marks specified entityId as removed and sets the origin project internal id to the given valuevoidmodifyConfigId(EntityId<INT> entityId, String newConfigId, CustomIdChangeApplier<String> configApplier)Modifies the given config identifier to the given new one.voidmodifyExternalId(EntityId<INT> entityId, String newExternalId, CustomIdChangeApplier<String> externalApplier)Modifies the given external identifier to the given new one.voidreassignInternalId(EntityId<INT> entityId, INT internalId, CustomIdChangeApplier<INT> applier)Assigns the specified internalId to the given entity and runs provided applier after that.voidreassignInternalIdInMemory(EntityId<INT> entityId, INT internalId)Reassigns internal id in memory only, does not change anything in database.EntityId<INT>refreshFromDbIfNecessary(String extId, String configId)Looks for a registered entity id by the given config id and ext id and refresh from db if necessary.StringregenerateExternalId(String parentExtId, String name, String currentExternalId)Regenerates an external id based on the given name and (optionally) parent external id.EntityId<INT>registerBrandNewExternalId(String extId)Registers the given external identifier with a brand new internal one.EntityId<INT>registerOrReuseExternalAndConfigId(String extId, String configId)Registers the given external identifier and config id pair.booleanremoveExternalIdAlias(String externalIdAlias)Removes the external id alias (but not a primary external id) from the model and database.voidresetRemoved(Collection<EntityId<INT>> entityIds)Resets removed mark for the given entityIdvoidvalidateExternalId(String extId, EntityId<INT> curObjId)Validates given external identifier
-
-
-
Constructor Detail
-
TemporaryIdentifiersManager
public TemporaryIdentifiersManager(@NotNull BaseIdentifiersManager<INT> delegate)
-
-
Method Detail
-
registerBrandNewExternalId
@NotNull public EntityId<INT> registerBrandNewExternalId(@NotNull String extId)
Description copied from interface:IdentifiersManagerRegisters the given external identifier with a brand new internal one. If such external identifier was already registered, the correspondent internal one is dropped (and is not reused).- Specified by:
registerBrandNewExternalIdin interfaceIdentifiersManager<INT>- Parameters:
extId- the external identifier to register.- Returns:
- new associated internal identifier.
-
registerOrReuseExternalAndConfigId
@NotNull public EntityId<INT> registerOrReuseExternalAndConfigId(@NotNull String extId, @Nullable String configId) throws InvalidIdentifierException
Description copied from interface:IdentifiersManagerRegisters the given external identifier and config id pair. If specified config id exists in database it's internal id will be used, otherwise new internal id will be generated.- Specified by:
registerOrReuseExternalAndConfigIdin interfaceIdentifiersManager<INT>- Parameters:
extId- the external identifier to register.configId- the config identifier to register, if null new config id is generated.- Returns:
- associated internal identifier.
- Throws:
InvalidIdentifierException
-
findEntityIdByConfigId
@Nullable public EntityId<INT> findEntityIdByConfigId(@NotNull String configId)
Description copied from interface:IdentifiersManagerLooks for a registered entity id by the given config id.- Specified by:
findEntityIdByConfigIdin interfaceIdentifiersManager<INT>- Parameters:
configId- config id, case insensitive.- Returns:
- found entity id or null when not found.
-
refreshFromDbIfNecessary
@Nullable public EntityId<INT> refreshFromDbIfNecessary(@NotNull String extId, @Nullable String configId)
Description copied from interface:IdentifiersManagerLooks for a registered entity id by the given config id and ext id and refresh from db if necessary. Called by secondary nodes while loading new entities- Specified by:
refreshFromDbIfNecessaryin interfaceIdentifiersManager<INT>- Returns:
- found entity id or null when not found.
-
findEntityIdByExternalId
@Nullable public EntityId<INT> findEntityIdByExternalId(@NotNull String extId)
Description copied from interface:IdentifiersManagerLooks for a registered entity id by the given external id.- Specified by:
findEntityIdByExternalIdin interfaceIdentifiersManager<INT>- Returns:
- found entity id or null when not found.
-
externalToInternal
@NotNull public List<INT> externalToInternal(@NotNull List<String> extIds)
Description copied from interface:IdentifiersManagerLooks for the internal identifiers by the given external ones- Specified by:
externalToInternalin interfaceIdentifiersManager<INT>- Parameters:
extIds- list of external IDs. Nulls are allowed.- Returns:
- List of internal IDs. List size is always equal to initial one. For unknown IDs null will be returned
-
externalToInternal
@Nullable public INT externalToInternal(@Nullable String extId)
Description copied from interface:IdentifiersManagerLooks for the internal identifier by the given external one.- Specified by:
externalToInternalin interfaceIdentifiersManager<INT>- Parameters:
extId- external identifier (case insensitive).- Returns:
- the internal identifier if found, or null if not found.
-
validateExternalId
public void validateExternalId(@NotNull String extId, @Nullable EntityId<INT> curObjId)Description copied from interface:IdentifiersManagerValidates given external identifier- Specified by:
validateExternalIdin interfaceIdentifiersManager<INT>- Parameters:
extId- identifier to validate
-
generateAndRegisterBrandNewExternalId
@NotNull public EntityId<INT> generateAndRegisterBrandNewExternalId(@Nullable String parentExtId, @NotNull String name) throws InvalidIdentifierException
Description copied from interface:IdentifiersManagerGenerates a unique external identifier by the given parent external identifier and a user string (usually name), and register the just generated identifier as a brand new one.- Specified by:
generateAndRegisterBrandNewExternalIdin interfaceIdentifiersManager<INT>- Parameters:
parentExtId- the parent's external identifier (optional).name- the user string (name).- Returns:
- just created identifiers pair.
- Throws:
InvalidIdentifierException
-
generateNewExternalId
@NotNull public String generateNewExternalId(@Nullable String parentExtId, @NotNull String name, @Nullable Set<String> excludeAdditionalIds)
Description copied from interface:ExternalIdGeneratorGenerates a new external id based on the given name and (optionally) parent external id. May adjust the case of the name part of the id to comply with external id conventions- Specified by:
generateNewExternalIdin interfaceExternalIdGenerator- Parameters:
parentExtId- the parent's external identifier (optional).name- the user string (name).excludeAdditionalIds- an additional set of ids that are already used (i.e. the result should not be one of them). The current assigned external ids are excluded by default.- Returns:
- new external id
-
generateNewExternalId
@NotNull public String generateNewExternalId(@Nullable String parentExtId, @NotNull String name, @Nullable Set<String> excludeIds, boolean adjustCase)
Description copied from interface:ExternalIdGeneratorGenerates a new external id based on the given name and (optionally) parent external id.- Specified by:
generateNewExternalIdin interfaceExternalIdGenerator- Parameters:
parentExtId- the parent's external identifier (optional).name- the user string (name).excludeIds- an additional set of ids that are already used (i.e. the result should not be one of them). The current assigned external ids are excluded by default.adjustCase- If true, the method is allowed to adjust the case of the name part of the external id- Returns:
- new external id
-
externalIdSatisfiesConvention
public boolean externalIdSatisfiesConvention(@NotNull String externalId, @NotNull String entityName, @NotNull String parentExtId)Description copied from interface:ExternalIdGeneratorReturns true if provided external id satisfies convention used to generate new ids- Specified by:
externalIdSatisfiesConventionin interfaceExternalIdGenerator- Parameters:
externalId- external ids to checkentityName- name of the entity whose external id is to be verifiedparentExtId- parent external id- Returns:
- see above
-
findEntityIdByInternalId
@Nullable public EntityId<INT> findEntityIdByInternalId(@NotNull INT intId)
Description copied from interface:IdentifiersManagerLooks for a registered entity id by the given internal id.- Specified by:
findEntityIdByInternalIdin interfaceIdentifiersManager<INT>- Parameters:
intId- internal id.- Returns:
- found entity id or null when not found.
-
modifyExternalId
public void modifyExternalId(@NotNull EntityId<INT> entityId, @NotNull String newExternalId, @Nullable CustomIdChangeApplier<String> externalApplier) throws DuplicateExternalIdException, NoSuchExternalIdExceptionDescription copied from interface:IdentifiersManagerModifies the given external identifier to the given new one.- Specified by:
modifyExternalIdin interfaceIdentifiersManager<INT>- Parameters:
entityId- the entity id where to modify its external id.newExternalId- the new external id.externalApplier- external procedure to make changes in files when successful.- Throws:
DuplicateExternalIdException- thrown when such external identifier already exists.NoSuchExternalIdException
-
modifyConfigId
public void modifyConfigId(@NotNull EntityId<INT> entityId, @NotNull String newConfigId, @Nullable CustomIdChangeApplier<String> configApplier) throws DuplicateConfigIdExceptionDescription copied from interface:IdentifiersManagerModifies the given config identifier to the given new one.- Specified by:
modifyConfigIdin interfaceIdentifiersManager<INT>- Parameters:
entityId- the entity id where to modify its config id.newConfigId- the new config id.configApplier- external procedure to make changes in files when successful.- Throws:
DuplicateConfigIdException
-
reassignInternalId
public void reassignInternalId(@NotNull EntityId<INT> entityId, @NotNull INT internalId, @Nullable CustomIdChangeApplier<INT> applier)Description copied from interface:IdentifiersManagerAssigns the specified internalId to the given entity and runs provided applier after that. The internalId should come from an entityId present in DB and marked as removed, otherwise anIllegalArgumentExceptionis thrown. Makes the extId of the given internalId becomes an alias for the entityId. Also creates a new deleted entity with extId='{entityId.extId}_Detached', intId={entityId.intId}, cfgId={entityId.cfgId}, so that {entityId.intId} can then be specified as internalId to in this method.- Specified by:
reassignInternalIdin interfaceIdentifiersManager<INT>
-
reassignInternalIdInMemory
public void reassignInternalIdInMemory(@NotNull EntityId<INT> entityId, @NotNull INT internalId)Description copied from interface:IdentifiersManagerReassigns internal id in memory only, does not change anything in database. Should be used in case of multi node event about internal id changes.- Specified by:
reassignInternalIdInMemoryin interfaceIdentifiersManager<INT>
-
removeExternalIdAlias
public boolean removeExternalIdAlias(@NotNull String externalIdAlias) throws FailedToRemoveExternalIdAliasDescription copied from interface:IdentifiersManagerRemoves the external id alias (but not a primary external id) from the model and database. If no nether alias nor internal id found, just silently returns.- Specified by:
removeExternalIdAliasin interfaceIdentifiersManager<INT>- Parameters:
externalIdAlias- the alias to remove.- Returns:
- whether the entry was really removed (from the database).
- Throws:
FailedToRemoveExternalIdAlias- when could not remove.
-
isExternalIdAlias
public boolean isExternalIdAlias(@NotNull String externalId)Description copied from interface:IdentifiersManagerCheck whether the external id is an alias (but not a primary external id).- Specified by:
isExternalIdAliasin interfaceIdentifiersManager<INT>- Parameters:
externalId- the external id to check.- Returns:
- whether the externalId is an alias
-
internalToExternal
@Nullable public String internalToExternal(@Nullable INT intId)
Description copied from interface:IdentifiersManagerLooks for the external identifier by the given internal one.- Specified by:
internalToExternalin interfaceIdentifiersManager<INT>- Parameters:
intId- internal identifier (case sensitive).- Returns:
- the external identifier if found, or null if not found.
-
internalToExternal
@NotNull public List<String> internalToExternal(@NotNull List<INT> intIds)
Description copied from interface:IdentifiersManagerLooks for the external identifiers by the given internal ones.- Specified by:
internalToExternalin interfaceIdentifiersManager<INT>- Parameters:
intIds- list of internal IDs. Nulls are allowed.- Returns:
- List of external IDs. List size is always equal to initial one. For unknown IDs null will be returned
-
configIdToInternal
@Nullable public INT configIdToInternal(@Nullable String configId)
Description copied from interface:IdentifiersManagerLooks for the internal identifier by the given config id.- Specified by:
configIdToInternalin interfaceIdentifiersManager<INT>- Parameters:
configId- config identifier (case insensitive).- Returns:
- the internal identifier if found, or null if not found.
-
getAllInternalIds
@NotNull public Set<INT> getAllInternalIds()
Description copied from interface:IdentifiersManagerProvides with all known internal identifiers.- Specified by:
getAllInternalIdsin interfaceIdentifiersManager<INT>- Returns:
- internal identifiers as a set of case-sensitive strings.
-
getAllExternalIds
@NotNull public Set<String> getAllExternalIds()
Description copied from interface:IdentifiersManagerProvides with all known external identifiers.- Specified by:
getAllExternalIdsin interfaceIdentifiersManager<INT>- Returns:
- external identifiers as a set of case-insensitive strings.
-
getAllExternalIds
@NotNull public Set<String> getAllExternalIds(@NotNull INT intId)
Description copied from interface:IdentifiersManagerReturns all external ids that correspond to theintId. There is a main one, or probably several aliases.If the
intIdis not found, empty set is returned.- Specified by:
getAllExternalIdsin interfaceIdentifiersManager<INT>- Parameters:
intId- internal identifier (case sensitive).- Returns:
- set of corresponding external ids
-
regenerateExternalId
@NotNull public String regenerateExternalId(@Nullable String parentExtId, @NotNull String name, @NotNull String currentExternalId)
Description copied from interface:ExternalIdGeneratorRegenerates an external id based on the given name and (optionally) parent external id. The current external id is not taken into account, so the result can be the current id (but with another case).- Specified by:
regenerateExternalIdin interfaceExternalIdGenerator- Parameters:
parentExtId- the parent's external identifier (optional).name- the user string (name).currentExternalId- the external id an object currently has- Returns:
- new external id
-
getNewOrChangedEntities
@NotNull public Collection<EntityId<INT>> getNewOrChangedEntities()
- Returns:
- all new entity ids as well as entity ids with modified external id
-
getNewEntities
@NotNull public Set<EntityId<INT>> getNewEntities()
- Returns:
- new entity ids, i.e. those with new internal identifier
-
markRemoved
public void markRemoved(@NotNull EntityId<INT> entityId, @Nullable String originProjectIntId)Description copied from interface:IdentifiersManagerMarks specified entityId as removed and sets the origin project internal id to the given value- Specified by:
markRemovedin interfaceIdentifiersManager<INT>
-
resetRemoved
public void resetRemoved(@NotNull Collection<EntityId<INT>> entityIds)Description copied from interface:IdentifiersManagerResets removed mark for the given entityId- Specified by:
resetRemovedin interfaceIdentifiersManager<INT>
-
consumeEntityIds
public void consumeEntityIds(@NotNull Consumer<EntityId<INT>> consumer)Description copied from interface:IdentifiersManagerConsumes entityIds in this manager- Specified by:
consumeEntityIdsin interfaceIdentifiersManager<INT>
-
-