Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Adobe-Consulting-Services/acs-aem…
Browse files Browse the repository at this point in the history
…-commons into feature/shared_props_resources

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
rbotha78 committed Mar 23, 2018
2 parents f2d68ae + 61eff59 commit 023d11e
Show file tree
Hide file tree
Showing 12 changed files with 387 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
### Changed
- #1284 - Expose the shared and global properties resources via bindings.

### Added

- #1237 - Reporting feature: Adding a report column for finding references to a resource

### Fixed

- #1286 - Error page handler now verifies parent resource is not a NonExistingResource
- #1288 - Restrict the redirect map file upload to .txt file extension

## [3.14.10] - 2018-03-08

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ private Resource findFirstRealParentOrSelf(SlingHttpServletRequest request, Reso

// Quick check for the Parent; Handles common case of deactivated pages
final Resource parent = resource.getParent();
if (parent != null) {
if (parent != null && !ResourceUtil.isNonExistingResource(resource)) {
log.debug("Found real aggregate resource via getParent() at [ {} ]", parent.getPath());
return parent;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2017 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.reports.models;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;

import com.adobe.acs.commons.reports.api.ReportCellCSVExporter;
import com.adobe.granite.references.Reference;
import com.adobe.granite.references.ReferenceAggregator;
import com.adobe.granite.references.ReferenceList;

@Model(adaptables = Resource.class)
public class ReferencesModel implements ReportCellCSVExporter {

@Inject
@OSGiService
private ReferenceAggregator aggregator;

private ReferenceList referenceList;

private Resource resource;

public ReferencesModel(Resource resource) {
this.resource = resource;
}

public List<Reference> getReferences() {
return referenceList;
}

@Override
public String getValue(Object result) {
resource = (Resource) result;
init();
List<String> refStrings = new ArrayList<String>();
for (Reference reference : referenceList) {
refStrings.add(reference.getType() + " - " + reference.getTarget().getPath());
}
return StringUtils.join(refStrings, ";");
}

@PostConstruct
public void init(){
referenceList = aggregator.createReferenceList(resource);
Iterator<Reference> references = referenceList.iterator();
while(references.hasNext()){
if(references.next().getTarget().getPath().equals(resource.getPath())){
references.remove();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
* #L%
*/
@aQute.bnd.annotation.Version("1.0.0")
@aQute.bnd.annotation.Version("1.1.0")
package com.adobe.acs.commons.reports.models;


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2017 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.reports.models;

import static org.junit.Assert.*;
import static org.mockito.Mockito.when;

import java.lang.reflect.Field;

import org.apache.sling.api.resource.Resource;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.acs.commons.reports.models.references.MockReferenceList;
import com.adobe.acs.commons.reports.models.references.MockReferencesAggregator;
import com.adobe.granite.references.Reference;
import com.adobe.granite.references.ReferenceAggregator;
import com.adobe.granite.references.ReferenceList;

public class ReferencesModelTest {

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

@Mock
private Resource mockResourceSource;

@Mock
private Resource mockResourceTarget;

private ReferencesModel referencesModel;

@Before
public void init()
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
log.info("init");

MockitoAnnotations.initMocks(this);

when(mockResourceSource.getPath()).thenReturn("/source");
when(mockResourceTarget.getPath()).thenReturn("/target");

ReferenceList references = new MockReferenceList(mockResourceSource);
references.add(new Reference(mockResourceSource, mockResourceTarget, "VALID"));
references.add(new Reference(mockResourceSource, mockResourceSource, "INVALID"));

ReferenceAggregator aggregator = new MockReferencesAggregator(references);

referencesModel = new ReferencesModel(mockResourceSource);
Field af = ReferencesModel.class.getDeclaredField("aggregator");
af.setAccessible(true);
af.set(referencesModel, aggregator);
referencesModel.init();
}

@Test
public void testGetReferences() throws IllegalAccessException {
log.info("testGetReferences");

assertNotNull(referencesModel.getReferences());
assertTrue(1 == referencesModel.getReferences().size());
assertEquals("/target", referencesModel.getReferences().get(0).getTarget().getPath());
assertEquals("VALID", referencesModel.getReferences().get(0).getType());

log.info("Test Successful!");
}

@Test
public void testGetValue() throws IllegalAccessException {
log.info("testGetValue");

assertNotNull(referencesModel.getValue(mockResourceSource));
assertEquals("VALID - /target", referencesModel.getValue(mockResourceSource));

log.info("Test Successful!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2017 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.reports.models.references;

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

import org.apache.sling.api.resource.Resource;

import com.adobe.granite.references.Reference;
import com.adobe.granite.references.ReferenceList;

public class MockReferenceList extends ArrayList<Reference> implements ReferenceList {

private static final long serialVersionUID = 1L;
private Resource resource;

public MockReferenceList(Resource resource) {
this.resource = resource;
}

@Override
public Resource getResource() {
return this.resource;
}

@Override
public List<Reference> subList(String... types) {
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2017 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.reports.models.references;

import java.util.Set;

import org.apache.sling.api.resource.Resource;

import com.adobe.granite.references.ReferenceAggregator;
import com.adobe.granite.references.ReferenceList;

public class MockReferencesAggregator implements ReferenceAggregator {

private ReferenceList referenceList;

public MockReferencesAggregator(ReferenceList referenceList){
this.referenceList = referenceList;
}

@Override
public ReferenceList createReferenceList(Resource resource) {
return referenceList;
}

@Override
public ReferenceList createReferenceList(Resource resource, String... types) {
return referenceList;
}

@Override
public Set<String> getTypes() {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<fmt:message key="Redirect Map File" /> *
</label>
<div class="coral-InputGroup coral-Form-field">
<input is="coral-Textfield" class="coral-InputGroup-input coral-Textfield" type="file" name="./redirectMap.txt" />
<input is="coral-Textfield" class="coral-InputGroup-input coral-Textfield" type="file" name="./redirectMap.txt" accept=".txt" />
</div>
<coral-icon class="coral-Form-fieldinfo coral-Icon coral-Icon--infoCircle coral-Icon--sizeS" icon="infoCircle" size="S" id="file-info" role="img" aria-label="info circle"></coral-icon>
<coral-tooltip variant="info" placement="right" target="#file-info" class="coral3-Tooltip coral3-Tooltip--info" aria-hidden="true" tabindex="-1" role="tooltip" style="display: none;">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Component"
jcr:title="ACS Commons Report Builder References Column"
componentGroup="ACS Commons - Report Builder Column"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Replication Status Column"
sling:resourceType="cq/gui/components/authoring/dialog"
helpPath="https://adobe-consulting-services.github.io/acs-aem-commons/features/reports">
<content
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/container">
<layout
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/layouts/fixedcolumns"/>
<items jcr:primaryType="nt:unstructured">
<column
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/container">
<items jcr:primaryType="nt:unstructured">
<heading
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldLabel="Heading"
name="./heading"
required="{Boolean}true"/>
<exporter
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/hidden"
name="./exporter"
value="com.adobe.acs.commons.reports.models.ReferencesModel" />
</items>
</column>
</items>
</content>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%--
#%L
ACS AEM Commons Package
%%
Copyright (C) 2017 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%
--%>
<%@include file="/libs/foundation/global.jsp" %><%
%>
<dl>
<dt>Heading</dt>
<dd>${properties.heading}</dd>
</dl>

0 comments on commit 023d11e

Please sign in to comment.