List of usage examples for java.util.regex Pattern matches
public static boolean matches(String regex, CharSequence input)
From source file:gov.usda.DataCatalogClient.Dataset.java
/** * bureau code must be in the following format 000:00 or NNN:NN. This validates. * This method is used from CKAN string. * @param bureauCode/*from ww w.java 2 s.c om*/ */ public void setBureauCodeList(String bureauCode) throws ParseException { if (!bureauCodeList.contains(bureauCode)) { if (Pattern.matches("\\d{3}:\\d{2}", bureauCode)) { bureauCodeList.add(bureauCode); } else { throw new ParseException("Bureau Code must be \\d{3}:\\d{2}: " + bureauCode, 2); } } }
From source file:gov.usda.DataCatalogClient.Dataset.java
/** * This is called from CKAN import/*w ww . j a v a 2 s . c o m*/ * @param programCode * @throws DatasetException */ public void setProgramCodeList(String programCode) throws ParseException { if (!programCodeList.contains(programCode)) { if (Pattern.matches("\\d{3}:\\d{3}", programCode)) { programCodeList.add(programCode); } else { //dsEx.addError("Program Code must be \\d{3}:\\d{3}: " + programCode); throw new ParseException("Program Code must be \\d{3}:\\d{3}: " + programCode, 3); } } }
From source file:com.stimulus.archiva.presentation.ConfigBean.java
protected void validateIPAddress(String value, String errorMessage) { if (value == null || value.trim().length() < 1) { ActionContext.getActionContext().addSimpleError(errorMessage); } else {/*from w w w. ja va2 s.co m*/ boolean matched = Pattern.matches(IPV4_REGEX, value) || Pattern.matches(IPV6_HEX4DECCOMPRESSED_REGEX, value) || Pattern.matches(IPV6_6HEX4DEC_REGEX, value) || Pattern.matches(IPV6_HEXCOMPRESSED_REGEX, value) || Pattern.matches(IPV6_REGEX, value); if (!matched) { ActionContext.getActionContext().addSimpleError(errorMessage); } } }
From source file:org.alfresco.repo.tenant.MultiTAdminServiceImpl.java
/** * @see #MAX_LEN/* w w w .j a va 2 s. c o m*/ * @see #REGEX_CONTAINS_ALPHA * @see #REGEX_VALID_DNS_LABEL */ protected void validateTenantName(String tenantDomain) { ParameterCheck.mandatory("tenantDomain", tenantDomain); if (tenantDomain.length() > MAX_LEN) { throw new IllegalArgumentException( tenantDomain + " is not a valid tenant name (must be less than " + MAX_LEN + " characters)"); } if (!Pattern.matches(REGEX_CONTAINS_ALPHA, tenantDomain)) { throw new IllegalArgumentException( tenantDomain + " is not a valid tenant name (must contain at least one alpha character)"); } String[] dnsLabels = tenantDomain.split("\\."); if (dnsLabels.length != 0) { for (int i = 0; i < dnsLabels.length; i++) { if (!Pattern.matches(REGEX_VALID_DNS_LABEL, dnsLabels[i])) { throw new IllegalArgumentException( dnsLabels[i] + " is not a valid DNS label (must match " + REGEX_VALID_DNS_LABEL + ")"); } } } else { if (!Pattern.matches(REGEX_VALID_DNS_LABEL, tenantDomain)) { throw new IllegalArgumentException( tenantDomain + " is not a valid DNS label (must match " + REGEX_VALID_DNS_LABEL + ")"); } } }
From source file:jp.primecloud.auto.service.impl.LoadBalancerServiceImpl.java
/** * {@inheritDoc}//from ww w. j a v a2 s . com */ @Override public void updateAwsLoadBalancer(Long loadBalancerNo, String loadBalancerName, String comment, Long componentNo, String subnetId, String securityGroupName, String availabilityZone, boolean internal) { // ? if (loadBalancerNo == null) { throw new AutoApplicationException("ECOMMON-000003", "loadBalancerNo"); } if (loadBalancerName == null || loadBalancerName.length() == 0) { throw new AutoApplicationException("ECOMMON-000003", "loadBalancerName"); } if (componentNo == null) { throw new AutoApplicationException("ECOMMON-000003", "componentNo"); } // ?? if (!Pattern.matches("^[0-9a-z]|[0-9a-z][0-9a-z-]*[0-9a-z]$", loadBalancerName)) { throw new AutoApplicationException("ECOMMON-000012", "loadBalancerName"); } // TODO: ?? // ??? LoadBalancer loadBalancer = loadBalancerDao.read(loadBalancerNo); AwsLoadBalancer awsLoadBalancer = awsLoadBalancerDao.read(loadBalancerNo); if (loadBalancer == null || awsLoadBalancer == null) { // ?????? throw new AutoApplicationException("ESERVICE-000603", loadBalancerNo); } // ??????? if (LoadBalancerStatus.fromStatus(loadBalancer.getStatus()) != LoadBalancerStatus.STOPPED) { // ?????????????????? if (!StringUtils.equals(loadBalancer.getLoadBalancerName(), loadBalancerName) || !componentNo.equals(loadBalancer.getComponentNo())) { throw new AutoApplicationException("ESERVICE-000604", loadBalancer.getLoadBalancerName()); } if (StringUtils.isEmpty(awsLoadBalancer.getSubnetId()) ? StringUtils.isNotEmpty(subnetId) : !StringUtils.equals(awsLoadBalancer.getSubnetId(), subnetId)) { throw new AutoApplicationException("ESERVICE-000604", loadBalancer.getLoadBalancerName()); } if (StringUtils.isEmpty(awsLoadBalancer.getSecurityGroups()) ? StringUtils.isNotEmpty(securityGroupName) : !StringUtils.equals(awsLoadBalancer.getSecurityGroups(), securityGroupName)) { throw new AutoApplicationException("ESERVICE-000604", loadBalancer.getLoadBalancerName()); } } // ????? if (!StringUtils.equals(loadBalancer.getLoadBalancerName(), loadBalancerName)) { // ?????? LoadBalancer checkLoadBalancer = loadBalancerDao .readByFarmNoAndLoadBalancerName(loadBalancer.getFarmNo(), loadBalancerName); if (checkLoadBalancer != null && !loadBalancerNo.equals(checkLoadBalancer.getLoadBalancerNo())) { // ???????? throw new AutoApplicationException("ESERVICE-000601", loadBalancerName); } // ???? Instance checkInstance = instanceDao.readByFarmNoAndInstanceName(loadBalancer.getFarmNo(), loadBalancerName); if (checkInstance != null) { // ??????? throw new AutoApplicationException("ESERVICE-000626", loadBalancerName); } } // ???? long countComponent = componentDao.countByComponentNo(componentNo); if (countComponent == 0) { // ??????? throw new AutoApplicationException("ESERVICE-000607", componentNo); } // ??????????? long countListener = loadBalancerListenerDao.countByLoadBalancerNo(loadBalancerNo); if (countListener > 0) { if (!loadBalancer.getComponentNo().equals(componentNo)) { // ???????? throw new AutoApplicationException("ESERVICE-000608"); } } Farm farm = farmDao.read(loadBalancer.getFarmNo()); //? if (loadBalancer.getComponentNo().equals(componentNo) == false || (StringUtils.isNotEmpty(awsLoadBalancer.getAvailabilityZone()) && StringUtils.equals(awsLoadBalancer.getAvailabilityZone(), availabilityZone) == false)) { //?????????EnableFalse?? List<LoadBalancerInstance> loadBalancerInstances = loadBalancerInstanceDao .readByLoadBalancerNo(loadBalancerNo); for (LoadBalancerInstance loadBalancerInstance : loadBalancerInstances) { loadBalancerInstance.setEnabled(false); loadBalancerInstanceDao.update(loadBalancerInstance); } } //AWS? awsLoadBalancer.setSubnetId(subnetId); awsLoadBalancer.setSecurityGroups(securityGroupName); awsLoadBalancer.setAvailabilityZone(availabilityZone); awsLoadBalancer.setInternal(internal); awsLoadBalancerDao.update(awsLoadBalancer); // ?? loadBalancer.setLoadBalancerName(loadBalancerName); loadBalancer.setComment(comment); loadBalancer.setFqdn(loadBalancerName + "." + farm.getDomainName()); loadBalancer.setComponentNo(componentNo); loadBalancerDao.update(loadBalancer); // eventLogger.log(EventLogLevel.INFO, farm.getFarmNo(), farm.getFarmName(), null, null, null, null, "LoadBalancerUpdate", null, null, new Object[] { loadBalancerName }); }
From source file:com.cybrosys.scientific.EventListener.java
public static boolean isValidNumber(String strValue) { if (strValue.contains('\u2212' + "")) { strValue = strValue.replace('\u2212', '-'); }//from w w w. j a v a2 s .co m final String Digits = "(\\p{Digit}+)"; final String HexDigits = "(\\p{XDigit}+)"; final String Exp = "[eE][+-]?" + Digits; final String fpRegex = ("[\\x00-\\x20]*" + "[+-]?(" + "NaN|" + "Infinity|" + "(((" + Digits + "(\\.)?(" + Digits + "?)(" + Exp + ")?)|" + "(\\.(" + Digits + ")(" + Exp + ")?)|" + "((" + "(0[xX]" + HexDigits + "(\\.)?)|" + "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" + ")[pP][+-]?" + Digits + "))" + "[fFdD]?))" + "[\\x00-\\x20]*"); if (Pattern.matches(fpRegex, strValue)) { Double.valueOf(strValue); return true; } else { return false; } }
From source file:com.microsoft.azure.management.resources.DeploymentOperationsImpl.java
/** * Get a deployment./* www . j av a2s. c om*/ * * @param resourceGroupName Required. The name of the resource group to get. * The name is case insensitive. * @param deploymentName Required. The name of the deployment. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return Template deployment information. */ @Override public DeploymentGetResult get(String resourceGroupName, String deploymentName) throws IOException, ServiceException, URISyntaxException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (resourceGroupName != null && resourceGroupName.length() > 1000) { throw new IllegalArgumentException("resourceGroupName"); } if (Pattern.matches("^[-\\w\\._]+$", resourceGroupName) == false) { throw new IllegalArgumentException("resourceGroupName"); } if (deploymentName == null) { throw new NullPointerException("deploymentName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("resourceGroupName", resourceGroupName); tracingParameters.put("deploymentName", deploymentName); CloudTracing.enter(invocationId, this, "getAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/subscriptions/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/resourcegroups/"; url = url + URLEncoder.encode(resourceGroupName, "UTF-8"); url = url + "/deployments/"; url = url + URLEncoder.encode(deploymentName, "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-04-01-preview"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("Content-Type", "application/json; charset=utf-8"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DeploymentGetResult result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DeploymentGetResult(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { DeploymentExtended deploymentInstance = new DeploymentExtended(); result.setDeployment(deploymentInstance); JsonNode idValue = responseDoc.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); deploymentInstance.setId(idInstance); } JsonNode nameValue = responseDoc.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); deploymentInstance.setName(nameInstance); } JsonNode propertiesValue = responseDoc.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { DeploymentPropertiesExtended propertiesInstance = new DeploymentPropertiesExtended(); deploymentInstance.setProperties(propertiesInstance); JsonNode provisioningStateValue = propertiesValue.get("provisioningState"); if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) { String provisioningStateInstance; provisioningStateInstance = provisioningStateValue.getTextValue(); propertiesInstance.setProvisioningState(provisioningStateInstance); } JsonNode correlationIdValue = propertiesValue.get("correlationId"); if (correlationIdValue != null && correlationIdValue instanceof NullNode == false) { String correlationIdInstance; correlationIdInstance = correlationIdValue.getTextValue(); propertiesInstance.setCorrelationId(correlationIdInstance); } JsonNode timestampValue = propertiesValue.get("timestamp"); if (timestampValue != null && timestampValue instanceof NullNode == false) { Calendar timestampInstance; timestampInstance = DatatypeConverter.parseDateTime(timestampValue.getTextValue()); propertiesInstance.setTimestamp(timestampInstance); } JsonNode outputsValue = propertiesValue.get("outputs"); if (outputsValue != null && outputsValue instanceof NullNode == false) { String outputsInstance; outputsInstance = outputsValue.getTextValue(); propertiesInstance.setOutputs(outputsInstance); } JsonNode providersArray = propertiesValue.get("providers"); if (providersArray != null && providersArray instanceof NullNode == false) { for (JsonNode providersValue : ((ArrayNode) providersArray)) { Provider providerInstance = new Provider(); propertiesInstance.getProviders().add(providerInstance); JsonNode idValue2 = providersValue.get("id"); if (idValue2 != null && idValue2 instanceof NullNode == false) { String idInstance2; idInstance2 = idValue2.getTextValue(); providerInstance.setId(idInstance2); } JsonNode namespaceValue = providersValue.get("namespace"); if (namespaceValue != null && namespaceValue instanceof NullNode == false) { String namespaceInstance; namespaceInstance = namespaceValue.getTextValue(); providerInstance.setNamespace(namespaceInstance); } JsonNode registrationStateValue = providersValue.get("registrationState"); if (registrationStateValue != null && registrationStateValue instanceof NullNode == false) { String registrationStateInstance; registrationStateInstance = registrationStateValue.getTextValue(); providerInstance.setRegistrationState(registrationStateInstance); } JsonNode resourceTypesArray = providersValue.get("resourceTypes"); if (resourceTypesArray != null && resourceTypesArray instanceof NullNode == false) { for (JsonNode resourceTypesValue : ((ArrayNode) resourceTypesArray)) { ProviderResourceType providerResourceTypeInstance = new ProviderResourceType(); providerInstance.getResourceTypes().add(providerResourceTypeInstance); JsonNode resourceTypeValue = resourceTypesValue.get("resourceType"); if (resourceTypeValue != null && resourceTypeValue instanceof NullNode == false) { String resourceTypeInstance; resourceTypeInstance = resourceTypeValue.getTextValue(); providerResourceTypeInstance.setName(resourceTypeInstance); } JsonNode locationsArray = resourceTypesValue.get("locations"); if (locationsArray != null && locationsArray instanceof NullNode == false) { for (JsonNode locationsValue : ((ArrayNode) locationsArray)) { providerResourceTypeInstance.getLocations() .add(locationsValue.getTextValue()); } } JsonNode apiVersionsArray = resourceTypesValue.get("apiVersions"); if (apiVersionsArray != null && apiVersionsArray instanceof NullNode == false) { for (JsonNode apiVersionsValue : ((ArrayNode) apiVersionsArray)) { providerResourceTypeInstance.getApiVersions() .add(apiVersionsValue.getTextValue()); } } JsonNode propertiesSequenceElement = ((JsonNode) resourceTypesValue .get("properties")); if (propertiesSequenceElement != null && propertiesSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = propertiesSequenceElement .getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String propertiesKey = property.getKey(); String propertiesValue2 = property.getValue().getTextValue(); providerResourceTypeInstance.getProperties().put(propertiesKey, propertiesValue2); } } } } } } JsonNode dependenciesArray = propertiesValue.get("dependencies"); if (dependenciesArray != null && dependenciesArray instanceof NullNode == false) { for (JsonNode dependenciesValue : ((ArrayNode) dependenciesArray)) { Dependency dependencyInstance = new Dependency(); propertiesInstance.getDependencies().add(dependencyInstance); JsonNode dependsOnArray = dependenciesValue.get("dependsOn"); if (dependsOnArray != null && dependsOnArray instanceof NullNode == false) { for (JsonNode dependsOnValue : ((ArrayNode) dependsOnArray)) { BasicDependency basicDependencyInstance = new BasicDependency(); dependencyInstance.getDependsOn().add(basicDependencyInstance); JsonNode idValue3 = dependsOnValue.get("id"); if (idValue3 != null && idValue3 instanceof NullNode == false) { String idInstance3; idInstance3 = idValue3.getTextValue(); basicDependencyInstance.setId(idInstance3); } JsonNode resourceTypeValue2 = dependsOnValue.get("resourceType"); if (resourceTypeValue2 != null && resourceTypeValue2 instanceof NullNode == false) { String resourceTypeInstance2; resourceTypeInstance2 = resourceTypeValue2.getTextValue(); basicDependencyInstance.setResourceType(resourceTypeInstance2); } JsonNode resourceNameValue = dependsOnValue.get("resourceName"); if (resourceNameValue != null && resourceNameValue instanceof NullNode == false) { String resourceNameInstance; resourceNameInstance = resourceNameValue.getTextValue(); basicDependencyInstance.setResourceName(resourceNameInstance); } } } JsonNode idValue4 = dependenciesValue.get("id"); if (idValue4 != null && idValue4 instanceof NullNode == false) { String idInstance4; idInstance4 = idValue4.getTextValue(); dependencyInstance.setId(idInstance4); } JsonNode resourceTypeValue3 = dependenciesValue.get("resourceType"); if (resourceTypeValue3 != null && resourceTypeValue3 instanceof NullNode == false) { String resourceTypeInstance3; resourceTypeInstance3 = resourceTypeValue3.getTextValue(); dependencyInstance.setResourceType(resourceTypeInstance3); } JsonNode resourceNameValue2 = dependenciesValue.get("resourceName"); if (resourceNameValue2 != null && resourceNameValue2 instanceof NullNode == false) { String resourceNameInstance2; resourceNameInstance2 = resourceNameValue2.getTextValue(); dependencyInstance.setResourceName(resourceNameInstance2); } } } JsonNode templateValue = propertiesValue.get("template"); if (templateValue != null && templateValue instanceof NullNode == false) { String templateInstance; templateInstance = templateValue.getTextValue(); propertiesInstance.setTemplate(templateInstance); } JsonNode templateLinkValue = propertiesValue.get("templateLink"); if (templateLinkValue != null && templateLinkValue instanceof NullNode == false) { TemplateLink templateLinkInstance = new TemplateLink(); propertiesInstance.setTemplateLink(templateLinkInstance); JsonNode uriValue = templateLinkValue.get("uri"); if (uriValue != null && uriValue instanceof NullNode == false) { URI uriInstance; uriInstance = new URI(uriValue.getTextValue()); templateLinkInstance.setUri(uriInstance); } JsonNode contentVersionValue = templateLinkValue.get("contentVersion"); if (contentVersionValue != null && contentVersionValue instanceof NullNode == false) { String contentVersionInstance; contentVersionInstance = contentVersionValue.getTextValue(); templateLinkInstance.setContentVersion(contentVersionInstance); } } JsonNode parametersValue = propertiesValue.get("parameters"); if (parametersValue != null && parametersValue instanceof NullNode == false) { String parametersInstance; parametersInstance = parametersValue.getTextValue(); propertiesInstance.setParameters(parametersInstance); } JsonNode parametersLinkValue = propertiesValue.get("parametersLink"); if (parametersLinkValue != null && parametersLinkValue instanceof NullNode == false) { ParametersLink parametersLinkInstance = new ParametersLink(); propertiesInstance.setParametersLink(parametersLinkInstance); JsonNode uriValue2 = parametersLinkValue.get("uri"); if (uriValue2 != null && uriValue2 instanceof NullNode == false) { URI uriInstance2; uriInstance2 = new URI(uriValue2.getTextValue()); parametersLinkInstance.setUri(uriInstance2); } JsonNode contentVersionValue2 = parametersLinkValue.get("contentVersion"); if (contentVersionValue2 != null && contentVersionValue2 instanceof NullNode == false) { String contentVersionInstance2; contentVersionInstance2 = contentVersionValue2.getTextValue(); parametersLinkInstance.setContentVersion(contentVersionInstance2); } } JsonNode modeValue = propertiesValue.get("mode"); if (modeValue != null && modeValue instanceof NullNode == false) { DeploymentMode modeInstance; modeInstance = Enum.valueOf(DeploymentMode.class, modeValue.getTextValue()); propertiesInstance.setMode(modeInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:fr.paris.lutece.plugins.plu.web.PluJspBean.java
/** * Generates a HTML form that displays the Atome manage * @param request the Http request//from www .ja v a2s. com * @return HTML */ public String getTreePluAtome(HttpServletRequest request) { int nIdPlu = Integer.parseInt(request.getParameter(PARAMETER_PLU_ID)); Plu plu = _pluServices.findByPrimaryKey(nIdPlu); if (plu == null) { plu = new Plu(); } Plu pluWork = _pluServices.findPluWork(); List<Plu> pluList = _pluServices.findAll(); _strCurrentPageIndex = Paginator.getPageIndex(request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex); _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt(PROPERTY_DEFAULT_RESULT_PER_PAGE, 10); _nItemsPerPage = Paginator.getItemsPerPage(request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage); Map<String, Object> model = new HashMap<String, Object>(); model.put(MARK_PLU, plu); model.put(MARK_PLU_WORK, pluWork); model.put(MARK_LIST_PLU_LIST, pluList); //Get the list of version with atome with a single version List<Version> listVersionWithAtomeWithSingleVersion = _versionServices .findVersionWithAtomeWithSingleVersion(); //gestion des atomes if (StringUtils.isNotEmpty(request.getParameter(PARAMETER_FOLDER_ID))) { setPageTitleProperty(PROPERTY_PAGE_TITLE_TREE_ATOME); int nIdFolder = 0; if (StringUtils.isNotEmpty(request.getParameter(PARAMETER_FOLDER_ID))) { nIdFolder = Integer.parseInt(request.getParameter(PARAMETER_FOLDER_ID)); } Folder folder = _folderServices.findByPrimaryKey(nIdFolder); if (folder == null) { folder = new Folder(); folder.setPlu(nIdPlu); } model.put(MARK_FOLDER, folder); if (request.getParameter(PARAMETER_FOLDER_TITLE) != null) { model.put(PARAMETER_FOLDER_TITLE, request.getParameter(PARAMETER_FOLDER_TITLE)); } String searchButtonName = I18nService.getLocalizedString(PROPERTY_SEARCH_ATOME_BUTTONSEARCH, I18nService.getDefaultLocale()); if (StringUtils.isBlank(request.getParameter(PARAMETER_BACK)) && ((StringUtils.isNotBlank(request.getParameter(PARAMETER_ATOME_NAME))) || (StringUtils.isNotBlank(request.getParameter(PARAMETER_ATOME_TITLE))) || (StringUtils.isNotBlank(request.getParameter(PARAMETER_ATOME_ID))) || (StringUtils.isNotBlank(request.getParameter(PARAMETER_VERSION_NUM))) || (StringUtils.isNotBlank(request.getParameter(PARAMETER_VERSION_D1))) || (StringUtils.isNotBlank(request.getParameter(PARAMETER_VERSION_D2))) || (StringUtils.isNotBlank(request.getParameter(PARAMETER_VERSION_D3))) || (StringUtils.isNotBlank(request.getParameter(PARAMETER_VERSION_D4))) || (StringUtils.isNotBlank(request.getParameter(searchButtonName))))) { String atomeName = request.getParameter(PARAMETER_ATOME_NAME); String atomeTitle = request.getParameter(PARAMETER_ATOME_TITLE); String strAtomeId = request.getParameter(PARAMETER_ATOME_ID); String strNumVersion = request.getParameter(PARAMETER_VERSION_NUM); String strD1 = request.getParameter(PARAMETER_VERSION_D1); String strD2 = request.getParameter(PARAMETER_VERSION_D2); String strD3 = request.getParameter(PARAMETER_VERSION_D3); String strD4 = request.getParameter(PARAMETER_VERSION_D4); if (request.getParameter(PARAMETER_CLEAR) != null) { atomeName = ""; atomeTitle = ""; strAtomeId = ""; strNumVersion = ""; } AtomeFilter atomeFilter = new AtomeFilter(); VersionFilter versionFilter = new VersionFilter(); if (!atomeName.equals("")) { atomeFilter.setName(atomeName); } if (!atomeTitle.equals("")) { atomeFilter.setTitle(atomeTitle); } if (!strAtomeId.equals("")) { Boolean p = Pattern.matches("[0-9]+?", strAtomeId); if (p) { int atomeId = Integer.parseInt(strAtomeId); atomeFilter.setId(atomeId); } else { return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_ATOME_ID_NUMBER, AdminMessage.TYPE_STOP); } } if (!strNumVersion.equals("")) { Boolean p = Pattern.matches("[0-9]+?", strNumVersion); if (p) { int numVersion = Integer.parseInt(strNumVersion); versionFilter.setVersion(numVersion); } else { return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_VERSION_NUMBER, AdminMessage.TYPE_STOP); } } if (!strD1.equals("")) { Date d1; try { d1 = stringToDate(strD1, "dd/MM/yyyy"); versionFilter.setD1(d1); } catch (ParseException e) { return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_DATE_FORMAT, AdminMessage.TYPE_STOP); } } if (!strD2.equals("")) { Date d2; try { d2 = stringToDate(strD2, "dd/MM/yyyy"); versionFilter.setD2(d2); } catch (ParseException e) { return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_DATE_FORMAT, AdminMessage.TYPE_STOP); } } if (!strD3.equals("")) { Date d3; try { d3 = stringToDate(strD3, "dd/MM/yyyy"); versionFilter.setD3(d3); } catch (ParseException e) { return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_DATE_FORMAT, AdminMessage.TYPE_STOP); } } if (!strD4.equals("")) { Date d4; try { d4 = stringToDate(strD4, "dd/MM/yyyy"); versionFilter.setD4(d4); } catch (ParseException e) { //throw new AppException( "An exception occured during date parsing", e ); } } List<Version> versionList = _versionServices.findByFilter(atomeFilter, versionFilter); //Set the version list to indicate if contain an atome with a single version this.setAtomeVersionHaveSingleVersion(listVersionWithAtomeWithSingleVersion, versionList); Paginator<Version> paginatorAtome = new Paginator<Version>((List<Version>) versionList, _nItemsPerPage, JSP_TREE_PLU_ATOME + "?id_plu=" + plu.getId() + "&id_folder=" + folder.getId() + "&atome_name=" + atomeName + "&atome_title=" + atomeTitle + "&id_atome=" + strAtomeId + "&num_version=" + strNumVersion + "&version_d1=" + strD1 + "&version_d2=" + strD2 + "&version_d3=" + strD3 + "&version_d4=" + strD4, PARAMETER_PAGE_INDEX, _strCurrentPageIndex); model.put(MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage); model.put(MARK_PAGINATOR_ATOME, paginatorAtome); model.put(MARK_LIST_VERSION_LIST, paginatorAtome.getPageItems()); model.put(PARAMETER_ATOME_NAME, atomeName); model.put(PARAMETER_ATOME_TITLE, atomeTitle); model.put(PARAMETER_ATOME_ID, strAtomeId); model.put(PARAMETER_VERSION_NUM, strNumVersion); model.put(PARAMETER_VERSION_D1, strD1); model.put(PARAMETER_VERSION_D2, strD2); model.put(PARAMETER_VERSION_D3, strD3); model.put(PARAMETER_VERSION_D4, strD4); } else { List<Version> versionList = new ArrayList<Version>(); if (nIdFolder > 0) { versionList = _versionServices.findByPluAndFolder(folder.getPlu(), nIdFolder); } else { versionList = _versionServices.findAll(); } //Set the version list to indicate if contain an atome with a single version this.setAtomeVersionHaveSingleVersion(listVersionWithAtomeWithSingleVersion, versionList); Paginator<Version> paginatorAtomeFind = new Paginator<Version>( (List<Version>) versionList, _nItemsPerPage, JSP_TREE_PLU_ATOME + "?id_plu=" + plu.getId() + "&id_folder=" + folder.getId() + "&atome_all=1", PARAMETER_PAGE_INDEX, _strCurrentPageIndex); model.put(MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage); model.put(MARK_PAGINATOR_ATOME, paginatorAtomeFind); model.put(MARK_LIST_VERSION_LIST, paginatorAtomeFind.getPageItems()); } } HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_TREE_PLU_ATOME, getLocale(), model); _fileList.clear(); _folderHtml.setHtml(null); _folderHtml.setHtmlImpression(null); _folderImage.setImg(null); return getAdminPage(template.getHtml()); }
From source file:jp.primecloud.auto.service.impl.InstanceServiceImpl.java
protected Long createInstance(Long farmNo, String instanceName, Long platformNo, String comment, Long imageNo) { // ?// www . jav a 2s. c o m if (farmNo == null) { throw new AutoApplicationException("ECOMMON-000003", "farmNo"); } if (instanceName == null || instanceName.length() == 0) { throw new AutoApplicationException("ECOMMON-000003", "instanceName"); } if (platformNo == null) { throw new AutoApplicationException("ECOMMON-000003", "platformNo"); } if (imageNo == null) { throw new AutoApplicationException("ECOMMON-000003", "imageNo"); } // ?? if (!Pattern.matches("^[0-9a-z]|[0-9a-z][0-9a-z-]*[0-9a-z]$", instanceName)) { throw new AutoApplicationException("ECOMMON-000012", "instanceName"); } // ??? Image image = imageDao.read(imageNo); Platform platform = platformDao.read(platformNo); if (platformNo.equals(image.getPlatformNo()) == false) { throw new AutoApplicationException("ESERVICE-000405", imageNo, platform.getPlatformName()); } // TODO: ?? // ????? Instance checkInstance = instanceDao.readByFarmNoAndInstanceName(farmNo, instanceName); if (checkInstance != null) { // ??????? throw new AutoApplicationException("ESERVICE-000401", instanceName); } // ????? LoadBalancer checkLoadBalancer = loadBalancerDao.readByFarmNoAndLoadBalancerName(farmNo, instanceName); if (checkLoadBalancer != null) { // ???????? throw new AutoApplicationException("ESERVICE-000417", instanceName); } // ?? Farm farm = farmDao.read(farmNo); if (farm == null) { throw new AutoApplicationException("ESERVICE-000406", farmNo); } // fqdn??? String fqdn = instanceName + "." + farm.getDomainName(); if (fqdn.length() > 63) { throw new AutoApplicationException("ESERVICE-000418", fqdn); } // TODO: ?? // VMware??Windows???VMware??????Windows???????? // TODO: OS?? if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform.getPlatformType()) && StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN)) { List<Instance> allInstances = instanceDao.readAll(); for (Instance instance2 : allInstances) { if (StringUtils.equals(instanceName, instance2.getInstanceName())) { Platform platform2 = platformDao.read(instance2.getPlatformNo()); if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform2.getPlatformType())) { Image image2 = imageDao.read(instance2.getImageNo()); if (StringUtils.startsWithIgnoreCase(image2.getOs(), PCCConstant.OS_NAME_WIN)) { // VMware?????Windows??? throw new AutoApplicationException("ESERVICE-000419", instanceName); } } } } } // ?? String instanceCode = passwordGenerator.generate(20); // ?? Instance instance = new Instance(); instance.setFarmNo(farmNo); instance.setInstanceName(instanceName); instance.setPlatformNo(platformNo); instance.setImageNo(imageNo); instance.setEnabled(false); instance.setComment(comment); instance.setFqdn(fqdn); instance.setInstanceCode(instanceCode); instance.setStatus(InstanceStatus.STOPPED.toString()); instanceDao.create(instance); // TODO: OS?? if (!StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN) || (StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN) && PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform.getPlatformType())) || (StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN) && PCCConstant.PLATFORM_TYPE_AZURE.equals(platform.getPlatformType())) || (StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN) && PCCConstant.PLATFORM_TYPE_OPENSTACK.equals(platform.getPlatformType()))) { // OpenStack?Puppet????? //if (!PCCConstant.PLATFORM_TYPE_OPENSTACK.equals(platform.getPlatformType())) { // Puppet?? PuppetInstance puppetInstance = new PuppetInstance(); puppetInstance.setInstanceNo(instance.getInstanceNo()); puppetInstanceDao.create(puppetInstance); //} } Boolean useZabbix = BooleanUtils.toBooleanObject(Config.getProperty("zabbix.useZabbix")); if (BooleanUtils.isTrue(useZabbix)) { // Zabbix?? ZabbixInstance zabbixInstance = new ZabbixInstance(); zabbixInstance.setInstanceNo(instance.getInstanceNo()); zabbixInstanceDao.create(zabbixInstance); } return instance.getInstanceNo(); }
From source file:uk.ac.ebi.intact.editor.controller.curate.publication.PublicationController.java
public void assignNewImex(ActionEvent evt) { // save publication changes first doSave(false);//w ww . j a va 2 s . c om registerEditorListenerIfNotDoneYet(); try { if (Pattern.matches(ImexCentralManager.PUBMED_REGEXP.toString(), publication.getPubmedId())) { getImexCentralManager().assignImexAndUpdatePublication(publication.getAc()); addInfoMessage("Successfully assigned new IMEx identifier to the publication " + publication.getShortLabel(), ""); } else { addErrorMessage( "Impossible to assign new IMEx id to unassigned publication. Must be assigned manually in IMEx central.", ""); } } catch (PublicationImexUpdaterException e) { addErrorMessage("Impossible to assign new IMEx id", e.getMessage()); } catch (EnricherException e) { IcentralFault f = null; if (e.getCause() instanceof IcentralFault) { f = (IcentralFault) e.getCause(); } else if (e.getCause().getCause() instanceof IcentralFault) { f = (IcentralFault) e.getCause().getCause(); } processImexCentralException(publication.getPubmedId(), e, f); } catch (Exception e) { addErrorMessage("Impossible to assign new IMEx id", e.getMessage()); } String ac = this.publication.getAc(); setPublication(null); setAc(ac); loadByAc(); getChangesController().removeFromUnsaved(publication, collectParentAcsOfCurrentAnnotatedObject()); imexId = this.publication.getImexId(); }