use of javax.annotation.Nullable in project sonarqube by SonarSource.
the class PermissionTemplateService method copyPermissions.
private void copyPermissions(DbSession dbSession, PermissionTemplateDto template, ComponentDto project, @Nullable Integer projectCreatorUserId) {
dbClient.resourceDao().updateAuthorizationDate(project.getId(), dbSession);
dbClient.groupPermissionDao().deleteByRootComponentId(dbSession, project.getId());
dbClient.userPermissionDao().deleteProjectPermissions(dbSession, project.getId());
List<PermissionTemplateUserDto> usersPermissions = dbClient.permissionTemplateDao().selectUserPermissionsByTemplateId(dbSession, template.getId());
String organizationUuid = template.getOrganizationUuid();
usersPermissions.forEach(up -> {
UserPermissionDto dto = new UserPermissionDto(organizationUuid, up.getPermission(), up.getUserId(), project.getId());
dbClient.userPermissionDao().insert(dbSession, dto);
});
List<PermissionTemplateGroupDto> groupsPermissions = dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateId(dbSession, template.getId());
groupsPermissions.forEach(gp -> {
GroupPermissionDto dto = new GroupPermissionDto().setOrganizationUuid(organizationUuid).setGroupId(isAnyone(gp.getGroupName()) ? null : gp.getGroupId()).setRole(gp.getPermission()).setResourceId(project.getId());
dbClient.groupPermissionDao().insert(dbSession, dto);
});
List<PermissionTemplateCharacteristicDto> characteristics = dbClient.permissionTemplateCharacteristicDao().selectByTemplateIds(dbSession, asList(template.getId()));
if (projectCreatorUserId != null) {
Set<String> permissionsForCurrentUserAlreadyInDb = usersPermissions.stream().filter(userPermission -> projectCreatorUserId.equals(userPermission.getUserId())).map(PermissionTemplateUserDto::getPermission).collect(java.util.stream.Collectors.toSet());
characteristics.stream().filter(PermissionTemplateCharacteristicDto::getWithProjectCreator).filter(characteristic -> !permissionsForCurrentUserAlreadyInDb.contains(characteristic.getPermission())).forEach(c -> {
UserPermissionDto dto = new UserPermissionDto(organizationUuid, c.getPermission(), projectCreatorUserId, project.getId());
dbClient.userPermissionDao().insert(dbSession, dto);
});
}
}
use of javax.annotation.Nullable in project sonarqube by SonarSource.
the class ActiveRuleChange method toDto.
public QProfileChangeDto toDto(@Nullable String login) {
QProfileChangeDto dto = new QProfileChangeDto();
dto.setChangeType(type.name());
dto.setProfileKey(getKey().qProfile());
dto.setLogin(login);
Map<String, String> data = new HashMap<>();
data.put("key", getKey().toString());
data.put("ruleKey", getKey().ruleKey().toString());
parameters.entrySet().stream().filter(param -> !param.getKey().isEmpty()).forEach(param -> data.put("param_" + param.getKey(), param.getValue()));
if (StringUtils.isNotEmpty(severity)) {
data.put("severity", severity);
}
if (inheritance != null) {
data.put("inheritance", inheritance.name());
}
dto.setData(data);
return dto;
}
use of javax.annotation.Nullable in project MinecraftForge by MinecraftForge.
the class ModelBlockAnimation method getPartTransform.
@Nullable
public TRSRTransformation getPartTransform(IModelState state, BlockPart part, int i) {
ImmutableCollection<MBJointWeight> infos = getJoint(i);
if (!infos.isEmpty()) {
Matrix4f m = new Matrix4f(), tmp;
float weight = 0;
for (MBJointWeight info : infos) {
if (info.getWeights().containsKey(i)) {
ModelBlockAnimation.MBJoint joint = new ModelBlockAnimation.MBJoint(info.getName(), part);
Optional<TRSRTransformation> trOp = state.apply(Optional.of(joint));
if (trOp.isPresent() && trOp.get() != TRSRTransformation.identity()) {
float w = info.getWeights().get(i)[0];
tmp = trOp.get().getMatrix();
tmp.mul(w);
m.add(tmp);
weight += w;
}
}
}
if (weight > 1e-5) {
m.mul(1f / weight);
return new TRSRTransformation(m);
}
}
return null;
}
use of javax.annotation.Nullable in project MinecraftForge by MinecraftForge.
the class FluidUtil method getFluidHandler.
/**
* Helper method to get an IFluidHandler for at a block position.
*
* Returns null if there is no valid fluid handler.
*/
@Nullable
public static IFluidHandler getFluidHandler(World world, BlockPos blockPos, @Nullable EnumFacing side) {
IBlockState state = world.getBlockState(blockPos);
Block block = state.getBlock();
if (block.hasTileEntity(state)) {
TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity != null && tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
return tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
}
} else if (block instanceof IFluidBlock) {
return new FluidBlockWrapper((IFluidBlock) block, world, blockPos);
} else if (block instanceof BlockLiquid) {
return new BlockLiquidWrapper((BlockLiquid) block, world, blockPos);
}
return null;
}
use of javax.annotation.Nullable in project MinecraftForge by MinecraftForge.
the class ForgeChunkManager method requestTicket.
/**
* Request a chunkloading ticket of the appropriate type for the supplied mod
*
* @param mod The mod requesting a ticket
* @param world The world in which it is requesting the ticket
* @param type The type of ticket
* @return A ticket with which to register chunks for loading, or null if no further tickets are available
*/
@Nullable
public static Ticket requestTicket(Object mod, World world, Type type) {
ModContainer container = getContainer(mod);
if (container == null) {
FMLLog.log(Level.ERROR, "Failed to locate the container for mod instance %s (%s : %x)", mod, mod.getClass().getName(), System.identityHashCode(mod));
return null;
}
String modId = container.getModId();
if (!callbacks.containsKey(modId)) {
FMLLog.severe("The mod %s has attempted to request a ticket without a listener in place", modId);
throw new RuntimeException("Invalid ticket request");
}
int allowedCount = getMaxTicketLengthFor(modId);
if (tickets.get(world).get(modId).size() >= allowedCount) {
if (!warnedMods.contains(modId)) {
FMLLog.info("The mod %s has attempted to allocate a chunkloading ticket beyond it's currently allocated maximum : %d", modId, allowedCount);
warnedMods.add(modId);
}
return null;
}
Ticket ticket = new Ticket(modId, type, world);
tickets.get(world).put(modId, ticket);
return ticket;
}
Aggregations