Search in sources :

Example 51 with Nullable

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);
        });
    }
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) StringUtils(org.apache.commons.lang.StringUtils) OrganizationPermission(org.sonar.db.permission.OrganizationPermission) DbSession(org.sonar.db.DbSession) GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) DefaultTemplatesResolverImpl(org.sonar.server.permission.ws.template.DefaultTemplatesResolverImpl) PermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateUserDto) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Arrays.asList(java.util.Arrays.asList) DefaultTemplatesResolver(org.sonar.server.permission.ws.template.DefaultTemplatesResolver) Nullable(javax.annotation.Nullable) PermissionIndexer(org.sonar.server.permission.index.PermissionIndexer) Iterator(java.util.Iterator) Collection(java.util.Collection) DefaultTemplates(org.sonar.db.organization.DefaultTemplates) Set(java.util.Set) Collectors(org.sonar.core.util.stream.Collectors) String.format(java.lang.String.format) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Qualifiers(org.sonar.api.resources.Qualifiers) PermissionTemplateCharacteristicDto(org.sonar.db.permission.template.PermissionTemplateCharacteristicDto) DefaultGroups.isAnyone(org.sonar.api.security.DefaultGroups.isAnyone) ServerSide(org.sonar.api.server.ServerSide) UserSession(org.sonar.server.user.UserSession) CheckForNull(javax.annotation.CheckForNull) UserPermissionDto(org.sonar.db.permission.UserPermissionDto) ComponentKeys(org.sonar.core.component.ComponentKeys) PermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateUserDto) PermissionTemplateCharacteristicDto(org.sonar.db.permission.template.PermissionTemplateCharacteristicDto) UserPermissionDto(org.sonar.db.permission.UserPermissionDto) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto)

Example 52 with Nullable

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;
}
Also used : QProfileChangeDto(org.sonar.db.qualityprofile.QProfileChangeDto) StringUtils(org.apache.commons.lang.StringUtils) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) Map(java.util.Map) MoreObjects(com.google.common.base.MoreObjects) HashMap(java.util.HashMap) Maps(com.google.common.collect.Maps) CheckForNull(javax.annotation.CheckForNull) Nullable(javax.annotation.Nullable) HashMap(java.util.HashMap) QProfileChangeDto(org.sonar.db.qualityprofile.QProfileChangeDto)

Example 53 with Nullable

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;
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) Matrix4f(javax.vecmath.Matrix4f) Nullable(javax.annotation.Nullable)

Example 54 with Nullable

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) BlockLiquidWrapper(net.minecraftforge.fluids.capability.wrappers.BlockLiquidWrapper) Block(net.minecraft.block.Block) Nullable(javax.annotation.Nullable)

Example 55 with Nullable

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;
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)735 IOException (java.io.IOException)85 Test (org.junit.Test)59 Map (java.util.Map)58 Function (com.google.common.base.Function)57 List (java.util.List)55 ArrayList (java.util.ArrayList)43 File (java.io.File)42 HashMap (java.util.HashMap)37 ItemStack (net.minecraft.item.ItemStack)36 ImmutableList (com.google.common.collect.ImmutableList)32 SkyKey (com.google.devtools.build.skyframe.SkyKey)28 Nonnull (javax.annotation.Nonnull)28 ImmutableMap (com.google.common.collect.ImmutableMap)27 Predicate (com.google.common.base.Predicate)26 URL (java.net.URL)22 Label (com.google.devtools.build.lib.cmdline.Label)21 HashSet (java.util.HashSet)20 Collectors (java.util.stream.Collectors)15 TypeElement (javax.lang.model.element.TypeElement)15