Example usage for java.util Objects isNull

List of usage examples for java.util Objects isNull

Introduction

In this page you can find the example usage for java.util Objects isNull.

Prototype

public static boolean isNull(Object obj) 

Source Link

Document

Returns true if the provided reference is null otherwise returns false .

Usage

From source file:org.kitodo.filemanagement.locking.LockManagement.java

/**
 * Checks if a user is allowed to open a read channel on the file. If the
 * user is authorized to read the file, the method silently returns and
 * nothing happens. If not, an {@code AccessDeniedException} is thrown with
 * a meaningful justification. However, if the user code previously
 * submitted a request for appropriate permissions and verified that the
 * answer was positive, then this case should never happen.
 *
 * <p>//from ww w . ja v  a 2  s  .  co m
 * In case the user gets read access due to an immutable read lock, this
 * method returns the URI to the temporary copy of the main file. The
 * subsequent file access process must therefore open the read channel to
 * this temporary copy, not to the main file.
 *
 * @param lockingResult
 *            which user requests the write channel
 * @param uri
 *            for which file the channel is requested
 * @param write
 *            if true, also check for permission to write, else read only
 * @return the URI to use. This is the same one that was passed, except for
 *         the immutable read lock, where it is the URI of the immutable
 *         read copy.
 * @throws AccessDeniedException
 *             if the user does not have sufficient authorization
 * @throws ProtocolException
 *             if the file had to be first read in again, but this step was
 *             skipped on the protocol. This error can occur with the
 *             UPGRADE_WRITE_ONCE lock because its protocol form requires
 *             that the file must first be read in again and the input
 *             stream must be closed after the lock has been upgraded.
 */
public URI checkPermission(LockResult lockingResult, URI uri, boolean write)
        throws AccessDeniedException, ProtocolException {
    GrantedAccess permissions = tryCast(lockingResult);
    logger.trace("{} wants to open a {} channel to {}.", permissions.getUser(), write ? "writing" : "reading",
            uri);
    try {
        GrantedPermissions granted = grantedPermissions.get(uri);
        if (Objects.isNull(granted)) {
            throw new AccessDeniedException(permissions.getUser() + " claims to have a privilege to " + uri
                    + " he does not have at all. Whatever he did, it was wrong.");
        }
        granted.checkAuthorization(permissions.getUser(), permissions.getLock(uri), write);
    } catch (AccessDeniedException e) {
        logger.trace("{} is not allowed to open a {} channel to {}. The reason is: {}", permissions.getUser(),
                write ? "writing" : "reading", uri, e.getMessage());
        throw e;
    }
    AbstractLock lock = permissions.getLock(uri);
    if (lock instanceof ImmutableReadLock) {
        uri = ((ImmutableReadLock) lock).getImmutableReadCopyURI();
    }
    logger.trace("{} is allowed to open a {} channel to {}.", permissions.getUser(),
            write ? "writing" : "reading", uri);
    return uri;
}

From source file:org.kitodo.production.services.data.TaskService.java

/**
 * Replace processing user for given task. Handles add/remove from list of
 * processing tasks./*from   w  w w .ja  v  a 2s  .  co  m*/
 *
 * @param task
 *            for which user will be assigned as processing user
 * @param user
 *            which will process given task
 */
public void replaceProcessingUser(Task task, User user) {
    User currentProcessingUser = task.getProcessingUser();

    if (Objects.isNull(user) && Objects.isNull(currentProcessingUser)) {
        logger.info("do nothing - there is not new nor old user");
    } else if (Objects.isNull(user)) {
        currentProcessingUser.getProcessingTasks().remove(task);
        task.setProcessingUser(null);
    } else if (Objects.isNull(currentProcessingUser)) {
        user.getProcessingTasks().add(task);
        task.setProcessingUser(user);
    } else if (Objects.equals(currentProcessingUser.getId(), user.getId())) {
        logger.info("do nothing - both are the same");
    } else {
        currentProcessingUser.getProcessingTasks().remove(task);
        user.getProcessingTasks().add(task);
        task.setProcessingUser(user);
    }
}

From source file:com.mac.holdempoker.app.impl.util.HandMatrix.java

/**
 * STRAIGHT/*from  w w w.  j  a va 2  s  .  c  o m*/
 *
 * @return
 */
private HandRank fHandRank() {
    Set<Rank> keys = rankHistogram.keySet();
    Rank[] ranks = keys.toArray(new Rank[keys.size()]);
    Rank[] cons = getConsecutiveRanks(ranks);
    if (Objects.isNull(cons) || cons.length < 5) {
        cons = getWheelRanks(ranks);
        if (Objects.isNull(cons)) {
            return null;
        }
    }
    List<Card> cards = new ArrayList();
    for (Rank r : cons) {
        Suit s = getSuitForRank(r);
        cards.add(makeCard(s, r));
    }
    Collections.sort(cards, this);
    return new SimpleHandRank(HandType.STRAIGHT, cards.toArray(new Card[5]));
}

From source file:org.kitodo.production.forms.MassImportForm.java

/**
 * File upload with binary copying./*from   w  ww. j  av a2s .  c o m*/
 */
public void uploadFile() throws IOException {
    if (Objects.isNull(this.uploadedFile)) {
        Helper.setErrorMessage("noFileSelected");
        return;
    }

    String basename = this.uploadedFile.getFileName();
    if (basename.startsWith(".")) {
        basename = basename.substring(1);
    }
    if (basename.contains("/")) {
        basename = basename.substring(basename.lastIndexOf('/') + 1);
    }
    if (basename.contains("\\")) {
        basename = basename.substring(basename.lastIndexOf('\\') + 1);
    }
    URI temporalFile = ServiceManager.getFileService().createResource(
            FilenameUtils.concat(ConfigCore.getParameterOrDefaultValue(ParameterCore.DIR_TEMP), basename));

    ServiceManager.getFileService().copyFile(URI.create(this.uploadedFile.getFileName()), temporalFile);
}

From source file:org.apache.streams.cassandra.CassandraPersistWriter.java

private void createKeyspaceAndTable() {
    Metadata metadata = client.cluster().getMetadata();
    if (Objects.isNull(metadata.getKeyspace(config.getKeyspace()))) {
        LOGGER.info("Keyspace {} does not exist. Creating Keyspace", config.getKeyspace());
        Map<String, Object> replication = new HashMap<>();
        replication.put("class", "SimpleStrategy");
        replication.put("replication_factor", 1);

        String createKeyspaceStmt = SchemaBuilder.createKeyspace(config.getKeyspace()).with()
                .replication(replication).getQueryString();
        client.cluster().connect().execute(createKeyspaceStmt);
    }/*  w  w w . ja v  a 2s  . c o  m*/

    session = client.cluster().connect(config.getKeyspace());

    KeyspaceMetadata ks = metadata.getKeyspace(config.getKeyspace());
    TableMetadata tableMetadata = ks.getTable(config.getTable());

    if (Objects.isNull(tableMetadata)) {
        LOGGER.info("Table {} does not exist in Keyspace {}. Creating Table", config.getTable(),
                config.getKeyspace());
        String createTableStmt = SchemaBuilder.createTable(config.getTable())
                .addPartitionKey(config.getPartitionKeyColumn(), DataType.varchar())
                .addColumn(config.getColumn(), DataType.blob()).getQueryString();

        session.execute(createTableStmt);
    }
}

From source file:org.esa.s3tbx.olci.radiometry.rayleigh.RayleighAux.java

public Map<Integer, double[]> getFourier() {
    if (Objects.isNull(fourierPoly)) {
        return fourierPoly = getFourierMap();
    }/*  ww  w  . j a v  a 2s  .co  m*/
    return fourierPoly;
}

From source file:org.kitodo.production.forms.WorkflowForm.java

/**
 * Create new workflow.//www.j  a  v  a2s . c om
 *
 * @return page
 */
public String newWorkflow() {
    this.workflow = new Workflow();
    this.workflow.setClient(ServiceManager.getUserService().getSessionClientOfAuthenticatedUser());
    return workflowEditPath + "&id=" + (Objects.isNull(this.workflow.getId()) ? 0 : this.workflow.getId());
}

From source file:org.goobi.production.cli.helper.CopyProcess.java

/**
 * Create Process.//from  w  w  w .  j av a2s .co m
 *
 * @param io
 *            import object
 * @return Process object
 */
public Process createProcess(ImportObject io) throws DataException, IOException {
    addProperties(io);
    updateTasks(this.prozessKopie);

    if (!io.getBatches().isEmpty()) {
        this.prozessKopie.getBatches().addAll(io.getBatches());
    }

    ServiceManager.getProcessService().save(this.prozessKopie);
    ServiceManager.getProcessService().refresh(this.prozessKopie);

    /*
     * wenn noch keine RDF-Datei vorhanden ist (weil keine Opac-Abfrage
     * stattfand, dann jetzt eine anlegen
     */
    if (Objects.isNull(this.myRdf)) {
        createNewFileformat();
    }

    ServiceManager.getFileService().writeMetadataFile(this.myRdf, this.prozessKopie);
    ServiceManager.getProcessService().readMetadataFile(this.prozessKopie);

    /* damit die Sortierung stimmt nochmal einlesen */
    ServiceManager.getProcessService().refresh(this.prozessKopie);
    return this.prozessKopie;
}

From source file:org.kitodo.production.helper.tasks.EmptyTask.java

/**
 * The function getTaskState() returns the task state. It can be one of
 * the followings:/*from   w  w  w.j av a 2s  .c  om*/
 *
 * <dl>
 * <dt><code>CRASHED</code></dt>
 * <dd>The thread has terminated abnormally. The field exception? is
 * holding the exception that has occurred.</dd>
 * <dt><code>FINISHED</code></dt>
 * <dd>The thread has finished its work without errors and is available for
 * clean-up.</dd>
 * <dt><code>NEW</code></dt>
 * <dd>The thread has not yet been started.</dd>
 * <dt><code>STOPPED</code></dt>
 * <dd>The thread was stopped by a front end userresulting in a call to its
 * {@link #interrupt(Behaviour)} method with {@link Behaviour}
 * .PREPARE_FOR_RESTART and is able to restart after cloning and replacing
 * it.</dd>
 * <dt><code>STOPPING</code></dt>
 * <dd>The thread has received a request to interrupt but didnt stop
 * yet.</dd>
 * <dt><code>WORKING</code></dt>
 * <dd>The thread is in operation.</dd>
 * </dl>
 *
 * @return the task state
 */
TaskState getTaskState() {
    switch (getState()) {
    case NEW:
        return TaskState.NEW;
    case TERMINATED:
        if (Objects.isNull(behaviour)) {
            behaviour = DEFAULT_BEHAVIOUR;
        }
        if (Objects.nonNull(exception)) {
            return TaskState.CRASHED;
        }
        if (Behaviour.PREPARE_FOR_RESTART.equals(behaviour)) {
            return TaskState.STOPPED;
        } else {
            return TaskState.FINISHED;
        }
    default:
        if (isInterrupted()) {
            return TaskState.STOPPING;
        } else {
            return TaskState.WORKING;
        }
    }
}

From source file:org.openecomp.sdc.translator.services.heattotosca.impl.NovaToVolResourceConnection.java

@Override
void addRequirementToConnectResources(Map.Entry<String, RequirementDefinition> entry, List<String> paramNames) {
    String paramName = paramNames.get(0);
    Optional<AttachedResourceId> attachedResourceId = HeatToToscaUtil.extractAttachedResourceId(translateTo,
            paramName);//  www  . ja  va 2s . c  o  m
    String node;
    if (!attachedResourceId.isPresent()) {
        return;
    }
    AttachedResourceId attachedResource = attachedResourceId.get();
    if (attachedResource.isGetResource()) {
        String volTranslatedId = (String) attachedResource.getTranslatedId();
        Resource volServerResource = HeatToToscaUtil.getResource(translateTo.getHeatOrchestrationTemplate(),
                volTranslatedId, translateTo.getHeatFileName());
        if (!StringUtils.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource(),
                volServerResource.getType())) {
            logger.warn("Volume attachment used from nested resource " + translateTo.getResourceId()
                    + " is pointing to incorrect resource type(" + volServerResource.getType()
                    + ") for relation through the parameter '" + paramName + "."
                    + " The connection to the volume is ignored. " + "Supported types are: "
                    + HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource());
            return;
        }
        node = volTranslatedId;
        createRequirementAssignment(entry, node, substitutionNodeTemplate);
    } else if (attachedResource.isGetParam()) {
        TranslatedHeatResource shareResource = translateTo.getContext().getHeatSharedResourcesByParam()
                .get(attachedResource.getEntityId());
        if (Objects.nonNull(shareResource)
                && !HeatToToscaUtil.isHeatFileNested(translateTo, translateTo.getHeatFileName())) {
            if (!StringUtils.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource(),
                    shareResource.getHeatResource().getType())) {
                logger.warn("Volume attachment used from nested resource " + translateTo.getResourceId()
                        + " is pointing to incorrect resource type(" + shareResource.getHeatResource().getType()
                        + ") for relation through the parameter '" + paramName + "."
                        + " The connection to the volume is ignored. " + "Supported types are: "
                        + HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource());
                return;
            }
            node = shareResource.getTranslatedId();
            createRequirementAssignment(entry, node, substitutionNodeTemplate);
        } else if (Objects.isNull(shareResource)) {
            List<FileData> allFilesData = translateTo.getContext().getManifest().getContent().getData();
            Optional<FileData> fileData = HeatToToscaUtil.getFileData(translateTo.getHeatFileName(),
                    allFilesData);
            if (fileData.isPresent()) {
                Optional<ResourceFileDataAndIDs> fileDataContainingResource = new VolumeTranslationHelper(
                        logger).getFileDataContainingVolume(fileData.get().getData(),
                                (String) attachedResource.getEntityId(), translateTo, FileData.Type.HEAT_VOL);
                if (fileDataContainingResource.isPresent()) {
                    createRequirementAssignment(entry,
                            fileDataContainingResource.get().getTranslatedResourceId(),
                            substitutionNodeTemplate);
                }
            }
        }
    }
}