<fim-prefix>icenses/LICENSE-2.0">Apache homepage</a>
 * <p>
 * Unless required by applicable law or agreed to in writing,<br>
 * software distributed under the License is distributed on an "AS IS" BASIS, <br>
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
 * See the License for the specific language governing permissions and <br>
 * limitations under the License.
 * <p>
 * Initial code contributed and copyrighted by<br>
 * 12.10.2011 by frentix GmbH, http://www.frentix.com
 * <p>
 */
package org.olat.modules.openmeetings.manager;

import java.io.StringWriter;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.persistence.TypedQuery;

import org.olat.core.commons.persistence.DB;
import org.olat.core.id.OLATResourceable;
import org.olat.core.util.xml.XStreamHelper;
import org.olat.group.BusinessGroup;
import org.olat.modules.openmeetings.model.OpenMeetingsRoom;
import org.olat.modules.openmeetings.model.OpenMeetingsRoomReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.CompactWriter;


/**
 * 
 * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
 */
@Service
public class OpenMeetingsDAO {

	@Autowired
	private DB dbInstance;
	
	private XStream xStream;
	
	@PostConstruct
	public void init() {
		xStream = XStreamHelper.createXStreamInstance();
		// BUG: CWE-91 XML Injection (aka Blind XPath Injection)
		// 
		// FIXED: 
<fim-middle>		XStreamHelper.allowDefaultPackage(xStream);
		xStream.alias("room", OpenMeetingsRoom.class);
		xStream.omitField(OpenMeetingsRoom.class, "property");
		xStream.omitField(OpenMeetingsRoom.class, "numO<fix-suffix>fUsers");
	}

	
	public OpenMeetingsRoomReference createReference(final BusinessGroup group, final OLATResourceable courseResource, String subIdentifier, OpenMeetingsRoom room) {
		String serialized = serializeRoom(room);
		OpenMeetingsRoomReference ref = new OpenMeetingsRoomReference();
		ref.setLastModified(new Date());
		ref.setRoomId(room.getRoomId());
		ref.setConfig(serialized);
		ref.setGroup(group);
		if(courseResource != null) {
			ref.setResourceTypeName(courseResource.getResourceableTypeName());
			ref.setResourceTypeId(courseResource.getResourceableId());
		}
		ref.setSubIdentifier(subIdentifier);
		dbInstance.getCurrentEntityManager().persist(ref);
		return ref;
	}

	public List<OpenMeetingsRoomReference> getReferences() {
		StringBuilder sb = new StringBuilder();
		sb.append("select ref from ").append(OpenMeetingsRoomReference.class.getName()).append(" ref");
		return dbInstance.getCurrentEntityManager().createQuery(sb.toString(), OpenMeetingsRoomReference.class).getResul<|endoftext|>