-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Adobe-Consulting-Services/acs-aem…
…-commons into feature/shared_props_resources # Conflicts: # CHANGELOG.md
- Loading branch information
Showing
12 changed files
with
387 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
bundle/src/main/java/com/adobe/acs/commons/reports/models/ReferencesModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
bundle/src/test/java/com/adobe/acs/commons/reports/models/ReferencesModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
bundle/src/test/java/com/adobe/acs/commons/reports/models/references/MockReferenceList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...c/test/java/com/adobe/acs/commons/reports/models/references/MockReferencesAggregator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...root/apps/acs-commons/components/utilities/report-builder/columns/references/.content.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"/> |
33 changes: 33 additions & 0 deletions
33
...cs-commons/components/utilities/report-builder/columns/references/_cq_dialog/.content.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
25 changes: 25 additions & 0 deletions
25
...ot/apps/acs-commons/components/utilities/report-builder/columns/references/references.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.