use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class JpaPortletEntityDao method getPortletEntities.
@Override
@DialectAwareTransactional(value = PostgreSQL81Dialect.class, exclude = false)
@PortalTransactionalReadOnly
@OpenEntityManager(unitName = PERSISTENCE_UNIT_NAME)
public Set<IPortletEntity> getPortletEntities(IPortletDefinitionId portletDefinitionId) {
Validate.notNull(portletDefinitionId, "portletEntity can not be null");
final IPortletDefinition portletDefinition = this.portletDefinitionDao.getPortletDefinition(portletDefinitionId);
final TypedQuery<PortletEntityImpl> query = this.createCachedQuery(this.findEntitiesForDefinitionQuery);
query.setParameter(this.portletDefinitionParameter, (PortletDefinitionImpl) portletDefinition);
final List<PortletEntityImpl> portletEntities = query.getResultList();
return new HashSet<IPortletEntity>(portletEntities);
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class JpaPortletDaoTest method testAllDefinitionDaoMethods.
@Test
public void testAllDefinitionDaoMethods() throws Exception {
final IPortletDefinitionId portletDefinitionId = execute(new Callable<IPortletDefinitionId>() {
@Override
public IPortletDefinitionId call() {
final IPortletType channelType = jpaChannelTypeDao.createPortletType("BaseType", "foobar");
//Create a definition
final IPortletDefinition chanDef1 = new PortletDefinitionImpl(channelType, "fname1", "Test Portlet 1", "Test Portlet 1 Title", "/context1", "portletName1", false);
jpaPortletDefinitionDao.savePortletDefinition(chanDef1);
//Try all of the retrieval options
final IPortletDefinition portDef1a = jpaPortletDefinitionDao.getPortletDefinition(chanDef1.getPortletDefinitionId());
jpaPortletDefinitionDao.savePortletDefinition(chanDef1);
assertEquals(chanDef1, portDef1a);
//Create a second definition with the same app/portlet
final IPortletDefinition chanDef2 = new PortletDefinitionImpl(channelType, "fname2", "Test Portlet 2", "Test Portlet 2 Title", "/uPortal", "portletName2", true);
jpaPortletDefinitionDao.savePortletDefinition(chanDef2);
return chanDef2.getPortletDefinitionId();
}
});
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final IPortletDefinition chanDef2 = jpaPortletDefinitionDao.getPortletDefinitionByFname("fname2");
// Add some preferences
final List<IPortletPreference> prefsList2 = chanDef2.getPortletPreferences();
prefsList2.add(new PortletPreferenceImpl("prefName1", false, "val1", "val2"));
prefsList2.add(new PortletPreferenceImpl("prefName2", true, "val3", "val4"));
jpaPortletDefinitionDao.savePortletDefinition(chanDef2);
}
});
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final IPortletDefinition chanDef2 = jpaPortletDefinitionDao.getPortletDefinitionByFname("fname2");
// verify preferences
final List<IPortletPreference> prefsList2 = chanDef2.getPortletPreferences();
assertEquals(2, prefsList2.size());
}
});
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
// Check prefs, remove one and another
final IPortletDefinition portDef3 = jpaPortletDefinitionDao.getPortletDefinitionByName("Test Portlet 2");
final List<IPortletPreference> prefsList3 = portDef3.getPortletPreferences();
final List<IPortletPreference> expectedPrefsList3 = new ArrayList<IPortletPreference>();
expectedPrefsList3.add(new PortletPreferenceImpl("prefName1", false, "val1", "val2"));
expectedPrefsList3.add(new PortletPreferenceImpl("prefName2", true, "val3", "val4"));
assertEquals(expectedPrefsList3, prefsList3);
prefsList3.remove(1);
prefsList3.add(new PortletPreferenceImpl("prefName3", false, "val5", "val6"));
jpaPortletDefinitionDao.savePortletDefinition(portDef3);
}
});
execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
// Check prefs
final IPortletDefinition portDef4 = jpaPortletDefinitionDao.getPortletDefinition(portletDefinitionId);
final List<IPortletPreference> prefsList4 = portDef4.getPortletPreferences();
final List<IPortletPreference> expectedPrefsList4 = new ArrayList<IPortletPreference>();
expectedPrefsList4.add(new PortletPreferenceImpl("prefName1", false, "val1", "val2"));
expectedPrefsList4.add(new PortletPreferenceImpl("prefName3", false, "val5", "val6"));
assertEquals(expectedPrefsList4, prefsList4);
}
});
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class JpaPortletDaoTest method testAllEntityDaoMethods.
@Test
public void testAllEntityDaoMethods() throws Exception {
final IPortletDefinitionId portletDefinitionId = execute(new Callable<IPortletDefinitionId>() {
@Override
public IPortletDefinitionId call() throws Exception {
final IPortletType channelType = jpaChannelTypeDao.createPortletType("BaseType", "foobar");
//Create a definition
final IPortletDefinition chanDef1 = new PortletDefinitionImpl(channelType, "fname1", "Test Portlet 1", "Test Portlet 1 Title", "/context1", "portletName1", false);
jpaPortletDefinitionDao.savePortletDefinition(chanDef1);
return chanDef1.getPortletDefinitionId();
}
});
final IPortletEntityId portletEntityId = execute(new Callable<IPortletEntityId>() {
@Override
public IPortletEntityId call() throws Exception {
IPortletEntity portEnt1 = jpaPortletEntityDao.createPortletEntity(portletDefinitionId, "chanSub1", 1);
return portEnt1.getPortletEntityId();
}
});
execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
final IPortletEntity portEnt1a = jpaPortletEntityDao.getPortletEntity(portletEntityId);
assertNotNull(portEnt1a);
final IPortletEntity portEnt1b = jpaPortletEntityDao.getPortletEntity("chanSub1", 1);
assertEquals(portEnt1a, portEnt1b);
final IPortletEntity portEnt1c = jpaPortletEntityDao.getPortletEntity("chanSub1", 1);
assertEquals(portEnt1b, portEnt1c);
final Set<IPortletEntity> portletEntities1 = jpaPortletEntityDao.getPortletEntities(portletDefinitionId);
assertEquals(Collections.singleton(portEnt1a), portletEntities1);
final Set<IPortletEntity> portletEntitiesByUser = jpaPortletEntityDao.getPortletEntitiesForUser(1);
assertEquals(Collections.singleton(portEnt1a), portletEntitiesByUser);
return null;
}
});
execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
//Add entity and preferences
final IPortletDefinition portDef1 = jpaPortletDefinitionDao.getPortletDefinition(portletDefinitionId);
portDef1.getPortletPreferences().add(new PortletPreferenceImpl("defpref1", false, "dpv1", "dpv2"));
jpaPortletDefinitionDao.savePortletDefinition(portDef1);
final IPortletEntity portEnt1 = jpaPortletEntityDao.getPortletEntity(portletEntityId);
portEnt1.getPortletPreferences().add(new PortletPreferenceImpl("entpref1", false, "epv1", "epv2"));
// portEnt1.setWindowState(WindowState.MINIMIZED);
jpaPortletEntityDao.updatePortletEntity(portEnt1);
return null;
}
});
execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
//Delete whole tree
final IPortletDefinition portDef2 = jpaPortletDefinitionDao.getPortletDefinition(portletDefinitionId);
jpaPortletDefinitionDao.deletePortletDefinition(portDef2);
return null;
}
});
execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
//Verify it is gone
final Set<IPortletEntity> portletEntities2 = jpaPortletEntityDao.getPortletEntities(portletDefinitionId);
assertEquals(Collections.emptySet(), portletEntities2);
return null;
}
});
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class GuestPortletEntityPreferencesImpl method loadBasePortletPreferences.
@Override
protected void loadBasePortletPreferences(IPortletEntity portletEntity, Map<String, IPortletPreference> basePortletPreferences) {
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
//Add descriptor prefs to base Map
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
final Preferences descriptorPreferences = portletDescriptor.getPortletPreferences();
for (final Preference preference : descriptorPreferences.getPortletPreferences()) {
final IPortletPreference preferenceWrapper = new PortletPreferenceImpl(preference);
basePortletPreferences.put(preferenceWrapper.getName(), preferenceWrapper);
}
//Add definition prefs to base Map
final List<IPortletPreference> definitionPreferences = portletDefinition.getPortletPreferences();
for (final IPortletPreference preference : definitionPreferences) {
basePortletPreferences.put(preference.getName(), preference);
}
//Add entity prefs to base Map
final List<IPortletPreference> entityPreferences = portletEntity.getPortletPreferences();
for (final IPortletPreference preference : entityPreferences) {
basePortletPreferences.put(preference.getName(), preference);
}
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletDefinitionPreferencesImpl method loadBasePortletPreferences.
@Override
protected void loadBasePortletPreferences(IPortletDefinition portletDefinition, Map<String, IPortletPreference> basePortletPreferences) {
//Add descriptor prefs to base Map
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
final Preferences descriptorPreferences = portletDescriptor.getPortletPreferences();
for (final Preference preference : descriptorPreferences.getPortletPreferences()) {
final IPortletPreference preferenceWrapper = new PortletPreferenceImpl(preference);
basePortletPreferences.put(preferenceWrapper.getName(), preferenceWrapper);
}
}
Aggregations