Example usage for org.apache.commons.validator.routines UrlValidator UrlValidator

List of usage examples for org.apache.commons.validator.routines UrlValidator UrlValidator

Introduction

In this page you can find the example usage for org.apache.commons.validator.routines UrlValidator UrlValidator.

Prototype

public UrlValidator() 

Source Link

Document

Create a UrlValidator with default properties.

Usage

From source file:org.jaqpot.core.service.resource.ModelResource.java

@POST
@Produces({ MediaType.APPLICATION_JSON })
@Path("/{id}")
@ApiOperation(value = "Creates Prediction", notes = "Creates Prediction", response = Task.class)
@org.jaqpot.core.service.annotations.Task
public Response makePrediction(
        // defaultValue = DEFAULT_DATASET
        @ApiParam(name = "dataset_uri", required = true) @FormParam("dataset_uri") String datasetURI,
        @FormParam("visible") Boolean visible, @PathParam("id") String id,
        @HeaderParam("subjectid") String subjectId) throws GeneralSecurityException, QuotaExceededException,
        ParameterIsNullException, ParameterInvalidURIException {

    if (datasetURI == null) {
        throw new ParameterIsNullException("datasetURI");
    }//from w  w w .j a v  a 2 s.  c  o  m
    if (id == null) {
        throw new ParameterIsNullException("id");
    }

    UrlValidator urlValidator = new UrlValidator();
    if (!urlValidator.isValid(datasetURI)) {
        throw new ParameterInvalidURIException("Not valid dataset URI.");
    }

    User user = userHandler.find(securityContext.getUserPrincipal().getName());
    long datasetCount = datasetHandler.countAllOfCreator(user.getId());
    int maxAllowedDatasets = new UserFacade(user).getMaxDatasets();

    if (datasetCount > maxAllowedDatasets) {
        LOG.info(String.format("User %s has %d datasets while maximum is %d", user.getId(), datasetCount,
                maxAllowedDatasets));
        throw new QuotaExceededException("Dear " + user.getId()
                + ", your quota has been exceeded; you already have " + datasetCount + " datasets. "
                + "No more than " + maxAllowedDatasets + " are allowed with your subscription.");
    }

    Model model = modelHandler.find(id);
    if (model == null) {
        throw new NotFoundException("Model not found.");
    }
    String datasetId = datasetURI.split("dataset/")[1];
    Dataset datasetMeta = datasetHandler.findMeta(datasetId);
    List<String> requiredFeatures = retrieveRequiredFeatures(model);

    parameterValidator.validateDataset(datasetMeta, requiredFeatures);

    Map<String, Object> options = new HashMap<>();
    options.put("dataset_uri", datasetURI);
    options.put("subjectid", subjectId);
    options.put("modelId", id);
    options.put("creator", securityContext.getUserPrincipal().getName());
    options.put("base_uri", uriInfo.getBaseUri().toString());
    Task task = predictionService.initiatePrediction(options);
    return Response.ok(task).build();
}

From source file:org.jaqpot.core.service.resource.ValidationResource.java

@POST
@Path("/training_test_cross")
@ApiOperation(value = "Creates Validation Report", notes = "Creates Validation Report", response = Task.class)
@org.jaqpot.core.service.annotations.Task
public Response crossValidateAlgorithm(@FormParam("algorithm_uri") String algorithmURI,
        @FormParam("training_dataset_uri") String datasetURI,
        @FormParam("algorithm_params") String algorithmParameters,
        @FormParam("prediction_feature") String predictionFeature,
        @ApiParam(name = "transformations", defaultValue = DEFAULT_TRANSFORMATIONS) @FormParam("transformations") String transformations,
        @ApiParam(name = "scaling", defaultValue = STANDARIZATION) @FormParam("scaling") String scaling, //, allowableValues = SCALING + "," + STANDARIZATION
        @FormParam("folds") Integer folds, @FormParam("stratify") String stratify,
        @FormParam("seed") Integer seed, @HeaderParam("subjectId") String subjectId)
        throws QuotaExceededException, JMSException, ParameterInvalidURIException, ParameterIsNullException {
    if (algorithmURI == null)
        throw new ParameterIsNullException("algorithmURI");
    if (datasetURI == null)
        throw new ParameterIsNullException("datasetURI");
    if (folds == null)
        throw new ParameterIsNullException("folds");

    User user = userHandler.find(securityContext.getUserPrincipal().getName());
    long reportCount = reportHandler.countAllOfCreator(user.getId());
    int maxAllowedReports = new UserFacade(user).getMaxReports();

    if (reportCount > maxAllowedReports) {
        LOG.info(String.format("User %s has %d algorithms while maximum is %d", user.getId(), reportCount,
                maxAllowedReports));/*from   w  ww .j a v a 2s.c o  m*/
        throw new QuotaExceededException("Dear " + user.getId()
                + ", your quota has been exceeded; you already have " + reportCount + " reports. "
                + "No more than " + maxAllowedReports + " are allowed with your subscription.");
    }

    UrlValidator urlValidator = new UrlValidator();
    if (!urlValidator.isValid(algorithmURI)) {
        throw new ParameterInvalidURIException("Not valid algorithm URI.");
    }
    if (!urlValidator.isValid(datasetURI)) {
        throw new ParameterInvalidURIException("Not valid dataset URI.");
    }
    if (!urlValidator.isValid(predictionFeature)) {
        throw new ParameterInvalidURIException("Not valid prediction feature URI.");
    }
    if (transformations != null && !transformations.isEmpty() && !urlValidator.isValid(transformations)) {
        throw new ParameterInvalidURIException("Not valid transformation URI.");
    }
    if (scaling != null && !scaling.isEmpty() && !urlValidator.isValid(scaling)) {
        throw new ParameterInvalidURIException("Not valid scaling URI.");
    }
    if ((stratify != null && !stratify.isEmpty() && !stratify.equals("random") && !stratify.equals("normal"))) {
        throw new BadRequestException("Not valid stratify option - choose between random and normal");
    }

    Task task = new Task(new ROG(true).nextString(12));
    task.setMeta(MetaInfoBuilder.builder().setCurrentDate()
            .addTitles("Validation on algorithm: " + algorithmURI).addComments("Validation task created")
            .addDescriptions("Validation task using algorithm " + algorithmURI + " and dataset " + datasetURI)
            .addCreators(securityContext.getUserPrincipal().getName()).build());
    task.setType(Task.Type.VALIDATION);
    task.setHttpStatus(202);
    task.setStatus(Task.Status.QUEUED);
    task.setVisible(Boolean.TRUE);
    Map<String, Object> options = new HashMap<>();
    options.put("taskId", task.getId());
    options.put("algorithm_uri", algorithmURI);
    options.put("dataset_uri", datasetURI);
    options.put("algorithm_params", algorithmParameters);
    options.put("prediction_feature", predictionFeature);
    options.put("folds", folds);
    options.put("stratify", stratify);
    options.put("seed", seed);
    options.put("creator", user.getId());
    options.put("subjectId", subjectId);

    Map<String, String> transformationAlgorithms = new LinkedHashMap<>();
    if (transformations != null && !transformations.isEmpty()) {
        transformationAlgorithms.put(uriInfo.getBaseUri().toString() + "algorithm/pmml",
                "{\"transformations\" : \"" + transformations + "\"}");
    }
    if (scaling != null && !scaling.isEmpty()) {
        transformationAlgorithms.put(scaling, "");
    }
    if (!transformationAlgorithms.isEmpty()) {
        String transformationAlgorithmsString = serializer.write(transformationAlgorithms);
        LOG.log(Level.INFO, "Transformations:{0}", transformationAlgorithmsString);
        options.put("transformations", transformationAlgorithmsString);
    }

    taskHandler.create(task);
    jmsContext.createProducer().setDeliveryDelay(1000).send(crossValidationQueue, options);

    return Response.ok(task).build();
}

From source file:org.jaqpot.core.service.resource.ValidationResource.java

@POST
@Path("/training_test_split")
@ApiOperation(value = "Creates Validation Report", notes = "Creates Validation Report", response = Task.class)
@org.jaqpot.core.service.annotations.Task
public Response splitValidateAlgorithm(@FormParam("algorithm_uri") String algorithmURI,
        @FormParam("training_dataset_uri") String datasetURI,
        @FormParam("algorithm_params") String algorithmParameters,
        @FormParam("prediction_feature") String predictionFeature,
        @ApiParam(name = "transformations", defaultValue = DEFAULT_TRANSFORMATIONS) @FormParam("transformations") String transformations,
        @ApiParam(name = "scaling", defaultValue = STANDARIZATION) @FormParam("scaling") String scaling, //, allowableValues = SCALING + "," + STANDARIZATION          
        @ApiParam(name = "split_ratio", required = true) @FormParam("split_ratio") Double splitRatio,
        @FormParam("stratify") String stratify, @FormParam("seed") Integer seed,
        @HeaderParam("subjectId") String subjectId)
        throws QuotaExceededException, JMSException, ParameterInvalidURIException, ParameterIsNullException {
    if (algorithmURI == null)
        throw new ParameterIsNullException("algorithmURI");
    if (datasetURI == null)
        throw new ParameterIsNullException("datasetURI");
    if (splitRatio == null)
        throw new ParameterIsNullException("splitRatio");

    User user = userHandler.find(securityContext.getUserPrincipal().getName());
    long reportCount = reportHandler.countAllOfCreator(user.getId());
    int maxAllowedReports = new UserFacade(user).getMaxReports();

    if (reportCount > maxAllowedReports) {
        LOG.info(String.format("User %s has %d reports while maximum is %d", user.getId(), reportCount,
                maxAllowedReports));//from   ww  w.  ja v  a2s . c om
        throw new QuotaExceededException("Dear " + user.getId()
                + ", your quota has been exceeded; you already have " + reportCount + " reports. "
                + "No more than " + maxAllowedReports + " are allowed with your subscription.");
    }

    UrlValidator urlValidator = new UrlValidator();
    if (!urlValidator.isValid(algorithmURI)) {
        throw new ParameterInvalidURIException("Not valid algorithm URI.");
    }
    if (!urlValidator.isValid(datasetURI)) {
        throw new ParameterInvalidURIException("Not valid dataset URI.");
    }
    if (!urlValidator.isValid(predictionFeature)) {
        throw new ParameterInvalidURIException("Not valid prediction feature URI.");
    }
    if (transformations != null && !transformations.isEmpty() && !urlValidator.isValid(transformations)) {
        throw new ParameterInvalidURIException("Not valid transformation URI.");
    }
    if (scaling != null && !scaling.isEmpty() && !urlValidator.isValid(scaling)) {
        throw new ParameterInvalidURIException("Not valid scaling URI.");
    }
    if ((stratify != null && !stratify.isEmpty() && !stratify.equals("random") && !stratify.equals("normal"))) {
        throw new BadRequestException("Not valid stratify option - choose between random and normal");
    }

    Task task = new Task(new ROG(true).nextString(12));
    task.setMeta(MetaInfoBuilder.builder().setCurrentDate()
            .addTitles("Validation on algorithm: " + algorithmURI).addComments("Validation task created")
            .addDescriptions("Validation task using algorithm " + algorithmURI + " and dataset " + datasetURI)
            .addCreators(securityContext.getUserPrincipal().getName()).build());
    task.setType(Task.Type.VALIDATION);
    task.setHttpStatus(202);
    task.setStatus(Task.Status.QUEUED);
    task.setVisible(Boolean.TRUE);
    Map<String, Object> options = new HashMap<>();
    options.put("taskId", task.getId());
    options.put("algorithm_uri", algorithmURI);
    options.put("dataset_uri", datasetURI);
    options.put("algorithm_params", algorithmParameters);
    options.put("prediction_feature", predictionFeature);
    options.put("scaling", scaling);
    options.put("split_ratio", splitRatio);
    options.put("stratify", stratify);
    options.put("seed", seed);
    options.put("type", "SPLIT");
    options.put("subjectId", subjectId);

    Map<String, String> transformationAlgorithms = new LinkedHashMap<>();
    if (transformations != null && !transformations.isEmpty()) {
        transformationAlgorithms.put(uriInfo.getBaseUri().toString() + "algorithm/pmml",
                "{\"transformations\" : \"" + transformations + "\"}");
    }
    if (scaling != null && !scaling.isEmpty()) {
        transformationAlgorithms.put(scaling, "");
    }
    if (!transformationAlgorithms.isEmpty()) {
        String transformationAlgorithmsString = serializer.write(transformationAlgorithms);
        LOG.log(Level.INFO, "Transformations:{0}", transformationAlgorithmsString);
        options.put("transformations", transformationAlgorithmsString);
    }

    taskHandler.create(task);
    System.out.println(splitValidationQueue.getTopicName());
    jmsContext.createProducer().setDeliveryDelay(1000).send(splitValidationQueue, options);
    return Response.ok(task).build();
}

From source file:org.jaqpot.core.service.resource.ValidationResource.java

@POST
@Path("/test_set_validation")
@ApiOperation(value = "Creates Validation Report", notes = "Creates Validation Report", response = Task.class)
@org.jaqpot.core.service.annotations.Task
public Response externalValidateAlgorithm(@FormParam("model_uri") String modelURI,
        @FormParam("test_dataset_uri") String datasetURI, @HeaderParam("subjectId") String subjectId)
        throws QuotaExceededException, ParameterIsNullException, ParameterInvalidURIException {
    if (modelURI == null)
        throw new ParameterIsNullException("modelURI");
    if (datasetURI == null)
        throw new ParameterIsNullException("datasetURI");

    User user = userHandler.find(securityContext.getUserPrincipal().getName());
    long reportCount = reportHandler.countAllOfCreator(user.getId());
    int maxAllowedReports = new UserFacade(user).getMaxReports();

    if (reportCount > maxAllowedReports) {
        LOG.info(String.format("User %s has %d algorithms while maximum is %d", user.getId(), reportCount,
                maxAllowedReports));/*from   w w  w  . j a  v  a  2  s.  co m*/
        throw new QuotaExceededException("Dear " + user.getId()
                + ", your quota has been exceeded; you already have " + reportCount + " reports. "
                + "No more than " + maxAllowedReports + " are allowed with your subscription.");
    }

    UrlValidator urlValidator = new UrlValidator();
    if (!urlValidator.isValid(modelURI)) {
        throw new ParameterInvalidURIException("Not valid model URI.");
    }
    if (!urlValidator.isValid(datasetURI)) {
        throw new ParameterInvalidURIException("Not valid dataset URI.");
    }

    Task task = new Task(new ROG(true).nextString(12));
    task.setMeta(MetaInfoBuilder.builder().setCurrentDate().addTitles("Validation on model: " + modelURI)
            .addComments("Validation task created")
            .addDescriptions("Validation task using model " + modelURI + " and dataset " + datasetURI)
            .addCreators(securityContext.getUserPrincipal().getName()).build());
    task.setType(Task.Type.VALIDATION);
    task.setHttpStatus(202);
    task.setStatus(Task.Status.QUEUED);
    task.setVisible(Boolean.TRUE);
    Map<String, Object> options = new HashMap<>();
    options.put("taskId", task.getId());
    options.put("model_uri", modelURI);
    options.put("subjectId", subjectId);
    options.put("dataset_uri", datasetURI);
    options.put("base_uri", uriInfo.getBaseUri().toString());
    options.put("type", "EXTERNAL");
    options.put("subjectId", subjectId);
    options.put("creator", user.getId());

    taskHandler.create(task);
    jmsContext.createProducer().setDeliveryDelay(1000).send(externalValidationQueue, options);

    return Response.ok(task).build();
}

From source file:org.odftoolkit.odfdom.pkg.rdfa.URIExtractorImpl.java

public URIExtractorImpl(Resolver resolver, boolean isForSAX) {
    this.resolver = resolver;
    this.isForSAX = isForSAX;
    this.urlValidator = new UrlValidator();
}

From source file:org.openbaton.nfvo.core.api.NetworkServiceDescriptorManagement.java

/**
 * This operation allows submitting and validating a Network Service Descriptor (NSD), including
 * any related VNFFGD and VLD./* ww w  .  ja  va 2  s  .c om*/
 */
@Override
public NetworkServiceDescriptor onboard(NetworkServiceDescriptor networkServiceDescriptor, String projectId)
        throws NotFoundException, BadFormatException, NetworkServiceIntegrityException,
        CyclicDependenciesException {

    log.info("Staring onboarding process for NSD: " + networkServiceDescriptor.getName());
    UrlValidator urlValidator = new UrlValidator();

    nsdUtils.fetchExistingVnfd(networkServiceDescriptor);

    for (VirtualNetworkFunctionDescriptor vnfd : networkServiceDescriptor.getVnfd()) {
        vnfd.setProjectId(projectId);
        for (VirtualDeploymentUnit virtualDeploymentUnit : vnfd.getVdu()) {
            virtualDeploymentUnit.setProjectId(projectId);
        }
        if (vnfd.getLifecycle_event() != null)
            for (LifecycleEvent event : vnfd.getLifecycle_event()) {
                if (event == null) {
                    throw new NotFoundException("LifecycleEvent is null");
                } else if (event.getEvent() == null) {
                    throw new NotFoundException("Event in one LifecycleEvent does not exist");
                }
            }
        if (vnfd.getEndpoint() == null)
            vnfd.setEndpoint(vnfd.getType());
        if (vnfd.getVnfPackageLocation() != null) {
            if (urlValidator.isValid(vnfd.getVnfPackageLocation())) { // this is a script link
                VNFPackage vnfPackage = new VNFPackage();
                vnfPackage.setScriptsLink(vnfd.getVnfPackageLocation());
                vnfPackage.setName(vnfd.getName());
                vnfPackage.setProjectId(projectId);
                vnfPackage = vnfPackageRepository.save(vnfPackage);
                vnfd.setVnfPackageLocation(vnfPackage.getId());
            } else { // this is an id pointing to a package already existing
                // nothing to do here i think...
            }
        } else
            log.warn("vnfPackageLocation is null. Are you sure?");
    }

    log.info("Checking if Vnfm is running...");

    Iterable<VnfmManagerEndpoint> endpoints = vnfmManagerEndpointRepository.findAll();

    nsdUtils.checkEndpoint(networkServiceDescriptor, endpoints);

    log.trace("Creating " + networkServiceDescriptor);
    log.trace("Fetching Data");
    nsdUtils.fetchVimInstances(networkServiceDescriptor, projectId);
    log.trace("Fetched Data");

    log.debug("Checking integrity of NetworkServiceDescriptor");
    nsdUtils.checkIntegrity(networkServiceDescriptor);

    log.trace("Persisting VNFDependencies");
    nsdUtils.fetchDependencies(networkServiceDescriptor);
    log.trace("Persisted VNFDependencies");

    networkServiceDescriptor.setProjectId(projectId);
    networkServiceDescriptor = nsdRepository.save(networkServiceDescriptor);
    log.info("Created NetworkServiceDescriptor with id " + networkServiceDescriptor.getId());
    return networkServiceDescriptor;
}

From source file:org.openbaton.nfvo.core.utils.NSDUtils.java

public void checkIntegrity(VirtualNetworkFunctionDescriptor virtualNetworkFunctionDescriptor)
        throws NetworkServiceIntegrityException {
    UrlValidator urlValidator = new UrlValidator();

    /** check flavours and images */
    Set<String> flavors = new HashSet<>();
    Set<String> imageNames = new HashSet<>();
    Set<String> imageIds = new HashSet<>();
    Set<String> internalVirtualLink = new HashSet<>();
    //    Set<String> virtualLinkDescriptors = new HashSet<>();
    Set<String> names = new HashSet<>();
    names.clear();//from  w  ww.  j av a  2  s  . c o m
    internalVirtualLink.clear();

    if (virtualNetworkFunctionDescriptor.getName() == null
            || virtualNetworkFunctionDescriptor.getName().isEmpty()) {
        throw new NetworkServiceIntegrityException("Not found name of VNFD. Must be defined");
    }

    if (virtualNetworkFunctionDescriptor.getType() == null
            || virtualNetworkFunctionDescriptor.getType().isEmpty()) {
        throw new NetworkServiceIntegrityException(
                "Not found type of VNFD " + virtualNetworkFunctionDescriptor.getName());
    }

    if (virtualNetworkFunctionDescriptor.getDeployment_flavour() != null
            && !virtualNetworkFunctionDescriptor.getDeployment_flavour().isEmpty()) {
        for (DeploymentFlavour deploymentFlavour : virtualNetworkFunctionDescriptor.getDeployment_flavour()) {
            if (deploymentFlavour.getFlavour_key() != null && !deploymentFlavour.getFlavour_key().isEmpty()) {
                names.add(deploymentFlavour.getFlavour_key());
            } else {
                throw new NetworkServiceIntegrityException("Deployment flavor of VNFD "
                        + virtualNetworkFunctionDescriptor.getName() + " is not well defined");
            }
        }
    } else {
        for (VirtualDeploymentUnit vdu : virtualNetworkFunctionDescriptor.getVdu()) {
            if (vdu.getComputation_requirement() == null || vdu.getComputation_requirement().isEmpty()) {
                throw new NetworkServiceIntegrityException("Flavour must be set in VNFD or all VDUs: "
                        + virtualNetworkFunctionDescriptor.getName()
                        + ". Come on... check the PoP page and pick at least one " + "DeploymentFlavor");
            } else {
                names.add(vdu.getComputation_requirement());
            }
        }
    }

    if (virtualNetworkFunctionDescriptor.getEndpoint() == null
            || virtualNetworkFunctionDescriptor.getEndpoint().isEmpty()) {
        throw new NetworkServiceIntegrityException(
                "Not found endpoint in VNFD " + virtualNetworkFunctionDescriptor.getName());
    }
    if (virtualNetworkFunctionDescriptor.getVdu() == null
            || virtualNetworkFunctionDescriptor.getVdu().size() == 0)
        throw new NetworkServiceIntegrityException(
                "Not found any VDU defined in VNFD \" + virtualNetworkFunctionDescriptor.getName()");
    int i = 1;
    for (VirtualDeploymentUnit vdu : virtualNetworkFunctionDescriptor.getVdu()) {
        if (vdu.getVnfc() == null || vdu.getVnfc().size() == 0)
            throw new NetworkServiceIntegrityException(
                    "Not found any VNFC in VDU of VNFD " + virtualNetworkFunctionDescriptor.getName());
        if (vdu.getName() == null || vdu.getName().isEmpty()) {
            vdu.setName(virtualNetworkFunctionDescriptor.getName() + "-" + i);
            i++;
        }
        if (vdu.getVm_image() == null || vdu.getVm_image().isEmpty()) {
            throw new NetworkServiceIntegrityException(
                    "Not found image in a VDU of VNFD " + virtualNetworkFunctionDescriptor.getName());
        }
        vdu.setProjectId(virtualNetworkFunctionDescriptor.getProjectId());
    }

    if (virtualNetworkFunctionDescriptor.getVirtual_link() != null) {
        for (InternalVirtualLink vl : virtualNetworkFunctionDescriptor.getVirtual_link()) {
            if (vl.getName() == null || Objects.equals(vl.getName(), ""))
                throw new NetworkServiceIntegrityException(
                        "The vnfd: " + virtualNetworkFunctionDescriptor.getName()
                                + " has a virtual link with no name specified");
        }
    }

    if (virtualNetworkFunctionDescriptor.getLifecycle_event() != null) {
        for (LifecycleEvent event : virtualNetworkFunctionDescriptor.getLifecycle_event()) {
            if (event == null) {
                throw new NetworkServiceIntegrityException("LifecycleEvent is null");
            } else if (event.getEvent() == null) {
                throw new NetworkServiceIntegrityException("Event in one LifecycleEvent does not exist");
            }
        }
    }
    if (virtualNetworkFunctionDescriptor.getVirtual_link() != null) {
        for (InternalVirtualLink internalVirtualLink1 : virtualNetworkFunctionDescriptor.getVirtual_link()) {
            internalVirtualLink.add(internalVirtualLink1.getName());
        }
    } else {
        virtualNetworkFunctionDescriptor.setVirtual_link(new HashSet<InternalVirtualLink>());
    }

    if (virtualNetworkFunctionDescriptor.getVnfPackageLocation() != null) {
        if (urlValidator.isValid(virtualNetworkFunctionDescriptor.getVnfPackageLocation())) { // this is a script link
            VNFPackage vnfPackage = new VNFPackage();
            vnfPackage.setScriptsLink(virtualNetworkFunctionDescriptor.getVnfPackageLocation());
            vnfPackage.setName(virtualNetworkFunctionDescriptor.getName());
            vnfPackage.setProjectId(virtualNetworkFunctionDescriptor.getProjectId());
            vnfPackage = vnfPackageRepository.save(vnfPackage);
            virtualNetworkFunctionDescriptor.setVnfPackageLocation(vnfPackage.getId());
        }
    } else
        log.warn("vnfPackageLocation is null. Are you sure?");

    if (virtualNetworkFunctionDescriptor.getVdu() != null) {
        for (VirtualDeploymentUnit virtualDeploymentUnit : virtualNetworkFunctionDescriptor.getVdu()) {
            if (inAllVims.equals("in-all-vims")) {
                if (virtualDeploymentUnit.getVimInstanceName() != null
                        && !virtualDeploymentUnit.getVimInstanceName().isEmpty()) {
                    for (String vimName : virtualDeploymentUnit.getVimInstanceName()) {
                        VimInstance vimInstance = null;
                        for (VimInstance vi : vimRepository
                                .findByProjectId(virtualNetworkFunctionDescriptor.getProjectId())) {
                            if (vimName.equals(vi.getName())) {
                                vimInstance = vi;
                                log.debug("Got vim with auth: " + vimInstance.getAuthUrl());
                                break;
                            }
                        }

                        if (vimInstance == null) {
                            throw new NetworkServiceIntegrityException("Not found VIM with name " + vimName
                                    + " referenced by VNFD " + virtualNetworkFunctionDescriptor.getName()
                                    + " and VDU " + virtualDeploymentUnit.getName());
                        }

                        if (virtualDeploymentUnit.getScale_in_out() < 1) {
                            throw new NetworkServiceIntegrityException(
                                    "Regarding the VirtualNetworkFunctionDescriptor "
                                            + virtualNetworkFunctionDescriptor.getName()
                                            + ": in one of the VirtualDeploymentUnit, the scale_in_out"
                                            + " parameter (" + virtualDeploymentUnit.getScale_in_out()
                                            + ") must be at least 1");
                        }
                        if (virtualDeploymentUnit.getScale_in_out() < virtualDeploymentUnit.getVnfc().size()) {
                            throw new NetworkServiceIntegrityException(
                                    "Regarding the VirtualNetworkFunctionDescriptor "
                                            + virtualNetworkFunctionDescriptor.getName()
                                            + ": in one of the VirtualDeploymentUnit, the scale_in_out"
                                            + " parameter (" + virtualDeploymentUnit.getScale_in_out()
                                            + ") must not be less than the number of starting "
                                            + "VNFComponent: " + virtualDeploymentUnit.getVnfc().size());
                        }
                        if (vimInstance.getFlavours() == null)
                            throw new NetworkServiceIntegrityException(
                                    "No flavours found on your VIM instance, therefore it is not possible to on board your NSD");
                        for (DeploymentFlavour deploymentFlavour : vimInstance.getFlavours()) {
                            flavors.add(deploymentFlavour.getFlavour_key());
                        }

                        for (NFVImage image : vimInstance.getImages()) {
                            imageNames.add(image.getName());
                            imageIds.add(image.getExtId());
                        }

                        //All "names" must be contained in the "flavors"
                        if (!flavors.containsAll(names)) {
                            throw new NetworkServiceIntegrityException(
                                    "Regarding the VirtualNetworkFunctionDescriptor "
                                            + virtualNetworkFunctionDescriptor.getName()
                                            + ": in one of the VirtualDeploymentUnit, not all "
                                            + "DeploymentFlavour" + names
                                            + " are contained into the flavors of the vimInstance "
                                            + "chosen. Please choose one from: " + flavors);
                        }
                        if (virtualDeploymentUnit.getVm_image() != null) {
                            for (String image : virtualDeploymentUnit.getVm_image()) {
                                log.debug("Checking image: " + image);
                                if (!imageNames.contains(image) && !imageIds.contains(image)) {
                                    throw new NetworkServiceIntegrityException(
                                            "Regarding the VirtualNetworkFunctionDescriptor "
                                                    + virtualNetworkFunctionDescriptor.getName()
                                                    + ": in one of the VirtualDeploymentUnit, image" + image
                                                    + " is not contained into the images of the vimInstance "
                                                    + "chosen. Please choose one from: " + imageNames
                                                    + " or from " + imageIds);
                                }
                            }
                        }
                        flavors.clear();

                        //                for (VNFComponent vnfComponent : virtualDeploymentUnit.getVnfc()) {
                        //                  for (VNFDConnectionPoint connectionPoint : vnfComponent.getConnection_point()) {
                        //                    if (!internalVirtualLink.contains(
                        //                        connectionPoint.getVirtual_link_reference())) {
                        //                      throw new NetworkServiceIntegrityException(
                        //                          "Regarding the VirtualNetworkFunctionDescriptor "
                        //                              + virtualNetworkFunctionDescriptor.getName()
                        //                              + ": in one of the VirtualDeploymentUnit, the "
                        //                              + "virtualLinkReference "
                        //                              + connectionPoint.getVirtual_link_reference()
                        //                              + " of a VNFComponent is not contained in the "
                        //                              + "InternalVirtualLink "
                        //                              + internalVirtualLink);
                        //                    }
                        //                  }
                        //                }
                    }
                } else {
                    log.warn(
                            "Impossible to complete Integrity check because of missing VimInstances definition");
                }
            } else {
                log.error("" + inAllVims + " not yet implemented!");
                throw new UnsupportedOperationException("" + inAllVims + " not yet implemented!");
            }
        }
    } else {
        virtualNetworkFunctionDescriptor.setVdu(new HashSet<VirtualDeploymentUnit>());
    }
    //      if (!virtualLinkDescriptors.containsAll(internalVirtualLink)) {
    //        throw new NetworkServiceIntegrityException(
    //            "Regarding the VirtualNetworkFunctionDescriptor "
    //                + virtualNetworkFunctionDescriptor.getName()
    //                + ": the InternalVirtualLinks "
    //                + internalVirtualLink
    //                + " are not contained in the VirtualLinkDescriptors "
    //                + virtualLinkDescriptors);
    //      }
}

From source file:org.openecomp.sdc.common.util.ValidationUtils.java

public static boolean validateUrl(String url) {

    UrlValidator urlValidator = new UrlValidator();
    if (!urlValidator.isValid(url)) {
        return false;
    }//from   ww  w .j  a  v a 2 s.c  om
    if (NONE_UTF8_PATTERN.matcher(url).find()) {
        return false;
    }

    if (URL_INVALIDE_PATTERN.matcher(url).find()) {
        return false;
    }
    return true;

}

From source file:org.shadowmask.core.discovery.rules.UrlRule.java

@Override
public boolean evaluate() {
    if (value == null) {
        throw new DataDiscoveryException("Should fill the column value before fire inspect rules.");
    }//  w  ww  .j av  a 2s. c  om

    String urlValue = value;
    if (!(value.startsWith("http://") || value.startsWith("https://") || value.startsWith("ftp://"))) {
        urlValue = "http://" + value;
    }
    UrlValidator urlValidator = new UrlValidator();
    return urlValidator.isValid(urlValue);
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.restapi.validation.HostValidationRule.java

@Override
public void validate(MultiValueMap<String, String> request) {
    try {//w w w.  j  ava  2s  . co m
        formDataValidator.validateField(request, HOST_KEY);
        UrlValidator urlValidator = new UrlValidator();
        if (!urlValidator.isValid(request.get(HOST_KEY).get(0))) {
            throw new ValidationException("Url given in " + HOST_KEY + " form field is invalid");
        }

    } catch (IllegalArgumentException e) {
        throw new ValidationException(e);
    }
}