Skip to content

Commit

Permalink
Merge 01f8ef3 into 41047ce
Browse files Browse the repository at this point in the history
  • Loading branch information
klcodanr committed Nov 11, 2019
2 parents 41047ce + 01f8ef3 commit f8522d5
Show file tree
Hide file tree
Showing 64 changed files with 3,403 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bundle/pom.xml
Expand Up @@ -74,6 +74,8 @@
*
</Import-Package>
<Sling-Model-Packages>
com.adobe.acs.commons.cloudconfig,
com.adobe.acs.commons.marketo,
com.adobe.acs.commons.redirectmaps.models,
com.adobe.acs.commons.version.model,
com.adobe.acs.commons.wcm.comparisons.model,
Expand Down
@@ -0,0 +1,63 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2019 Adobe
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.adobe.acs.commons.cloudconfig;

import org.osgi.annotation.versioning.ConsumerType;

import com.drew.lang.annotations.NotNull;

/**
* Defines the {@code CloudConfiguration} Sling Model used for the cloudconfig
* component.
*/
@ConsumerType
public interface CloudConfiguration {

/**
* Get the path of the configuration containing the cloud configuration instance
*
* @return the path of the configuration containing the cloud configuration
* instance
*/
@NotNull
default String getConfigPath() {
throw new UnsupportedOperationException();
}

/**
* Get the path of the cloud configuration instance
*
* @return the path of the cloud configuration instance
*/
@NotNull
default String getItemPath() {
throw new UnsupportedOperationException();
}

/**
* Get the title of the cloud configuration instance
*
* @return the title of the cloud configuration instance
*/
@NotNull
default String getTitle() {
throw new UnsupportedOperationException();
}
}
@@ -0,0 +1,44 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2019 Adobe
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.adobe.acs.commons.cloudconfig;

import java.util.List;

import org.osgi.annotation.versioning.ConsumerType;

import com.drew.lang.annotations.NotNull;

/**
* Defines the {@code CloudConfigurationList} Sling Model used for the cloudconfig component.
*
*/
@ConsumerType
public interface CloudConfigurationList {

/**
* Retrieve the list of CloudConfigurations for the specified request.
*
* @return the list of {@code CloudConfiguration}s
*/
@NotNull
default List<CloudConfiguration> getCloudConfigurations() {
throw new UnsupportedOperationException();
}
}
@@ -0,0 +1,66 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2019 Adobe
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.adobe.acs.commons.cloudconfig.impl;

import java.util.Optional;

import javax.inject.Named;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;

import com.adobe.acs.commons.cloudconfig.CloudConfiguration;
import com.drew.lang.annotations.NotNull;

@Model(adaptables = Resource.class, adapters = { CloudConfiguration.class })
public class CloudConfigurationImpl implements CloudConfiguration {

private String configPath;
private String path;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
@Named("jcr:content/jcr:title")
private String title;

public CloudConfigurationImpl(Resource resource) {
path = resource.getPath();
configPath = Optional.ofNullable(resource.getParent()).map(Resource::getParent).map(Resource::getPath).orElse("");
}

@NotNull
@Override
public String getConfigPath() {
return configPath;
}

@NotNull
@Override
public String getItemPath() {
return path;
}

@NotNull
@Override
public String getTitle() {
return title;
}
}
@@ -0,0 +1,68 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2019 Adobe
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.adobe.acs.commons.cloudconfig.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import javax.jcr.query.Query;

import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.acs.commons.cloudconfig.CloudConfiguration;
import com.adobe.acs.commons.cloudconfig.CloudConfigurationList;
import com.drew.lang.annotations.NotNull;

@Model(adaptables = SlingHttpServletRequest.class, adapters = { CloudConfigurationList.class })
public class CloudConfigurationListImpl implements CloudConfigurationList {

private static final Logger log = LoggerFactory.getLogger(CloudConfigurationListImpl.class);

private List<CloudConfiguration> configs = new ArrayList<>();

public CloudConfigurationListImpl(SlingHttpServletRequest slingRequest) {

String template = Optional.ofNullable(slingRequest.getRequestPathInfo().getSuffix()).orElse("");

if (StringUtils.isNotBlank(template)) {
String query = "SELECT * FROM [cq:Page] WHERE ISDESCENDANTNODE([/conf]) AND [jcr:content/cq:template]='"
+ template.replace("'", "''") + "'";
log.debug("Finding cloud configuerations with: {}", query);

slingRequest.getResourceResolver().findResources(query, Query.JCR_SQL2).forEachRemaining(ccr -> {
configs.add(ccr.adaptTo(CloudConfiguration.class));
});
} else {
log.debug("Suffix not specified");

}
}

@NotNull
@Override
public List<CloudConfiguration> getCloudConfigurations() {
return configs;
}
}
@@ -0,0 +1,104 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2019 Adobe
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.adobe.acs.commons.cloudconfig.impl;

import java.io.IOException;
import java.util.Collections;

import javax.annotation.Nonnull;
import javax.servlet.Servlet;

import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.servlets.post.HtmlResponse;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.aemds.guide.utils.JcrResourceConstants;
import com.day.cq.commons.jcr.JcrConstants;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.WCMException;

@Component(service = Servlet.class, property = { "sling.servlet.methods=" + HttpConstants.METHOD_POST,
"sling.servlet.resourceTypes=acs-commons/components/utilities/cloudconfig/cloudconfiglist" })
public class CreateCloudConfigServlet extends SlingAllMethodsServlet {

private static final long serialVersionUID = -397622433323474345L;
private static final Logger log = LoggerFactory.getLogger(CreateCloudConfigServlet.class);

@Override
protected void doPost(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response)
throws IOException {
ResourceResolver resolver = request.getResourceResolver();
PageManager pageManager = resolver.adaptTo(PageManager.class);

HtmlResponse resp = new HtmlResponse();

if (pageManager == null) {
resp.setError(new IOException("Unable to get page manager"));
} else {

String configPath = getParam(request, "configPath");
Resource cloudConfigFolder = ResourceUtil.getOrCreateResource(resolver, configPath + "/settings/cloudconfigs",
Collections.singletonMap(JcrConstants.JCR_PRIMARYTYPE, JcrResourceConstants.NT_SLING_FOLDER),
JcrResourceConstants.NT_SLING_FOLDER, false);
log.debug("Creating Cloud Config in: {}", cloudConfigFolder);

resp.setParentLocation(cloudConfigFolder.getPath());

// create a new page
Page page;
try {
page = pageManager.create(cloudConfigFolder.getPath(), getParam(request, "name"), getParam(request, "template"),
getParam(request, "title"));
resp.setPath(page.getPath());
resp.setLocation(page.getPath());
resp.setStatus(200, "Created Cloud Configuration");
log.debug("Created configuration: {}", page.getPath());
resolver.commit();
} catch (WCMException e) {
resp.setError(e);
}

}
response.setContentType("text/plain");
resp.send(response, true);

}

private String getParam(SlingHttpServletRequest request, String param) throws IOException {
String value = request.getParameter(param);
if (StringUtils.isBlank(value)) {
throw new IOException("Parameter " + param + " must not be blank");
} else {
log.debug("Loaded {} for parameter {}", value, param);
}
return value;
}

}
40 changes: 40 additions & 0 deletions bundle/src/main/java/com/adobe/acs/commons/marketo/FormValue.java
@@ -0,0 +1,40 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2019 Adobe
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.adobe.acs.commons.marketo;

/**
* A Model representing setting a form value in the Marketo form.
*/
public interface FormValue {


default String getName() {
throw new UnsupportedOperationException();
}

default String getSource() {
throw new UnsupportedOperationException();
}

default String getValue() {
throw new UnsupportedOperationException();
}

}

0 comments on commit f8522d5

Please sign in to comment.